private void Disable(AttachmentType type) { var solver = m_Actor.solver; var blueprint = m_Actor.blueprint; if (isBound && blueprint != null && solver != null) { switch (type) { case AttachmentType.Dynamic: var pins = m_Actor.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints <ObiPinConstraintsBatch>; if (pins != null && pinBatch != null) { pinBatch.SetEnabled(false); pinBatch.RemoveFromSolver(); pins.RemoveBatch(pinBatch); pinBatch = null; } break; case AttachmentType.Static: for (int i = 0; i < m_SolverIndices.Length; ++i) { if (m_SolverIndices[i] >= 0 && m_SolverIndices[i] < solver.invMasses.count) { solver.invMasses[m_SolverIndices[i]] = blueprint.invMasses[i]; } } if (m_Actor.usesOrientedParticles) { for (int i = 0; i < m_SolverIndices.Length; ++i) { if (m_SolverIndices[i] >= 0 && m_SolverIndices[i] < solver.invRotationalMasses.count) { solver.invRotationalMasses[m_SolverIndices[i]] = blueprint.invRotationalMasses[i]; } } } m_Actor.UpdateParticleProperties(); break; } } }
private void Enable(AttachmentType type) { var solver = m_Actor.solver; var blueprint = m_Actor.blueprint; if (isBound && blueprint != null && m_Actor.solver != null) { switch (type) { case AttachmentType.Dynamic: var pins = m_Actor.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints <ObiPinConstraintsBatch>; ObiColliderBase attachedCollider = m_Target.GetComponent <ObiColliderBase>(); if (pins != null && attachedCollider != null) { // create a new data batch with all our pin constraints: pinBatch = new ObiPinConstraintsBatch(); for (int i = 0; i < m_PositionOffsets.Length; ++i) { pinBatch.AddConstraint(0, attachedCollider, m_PositionOffsets[i], m_OrientationOffsets[i]); pinBatch.activeConstraintCount++; } // add the batch to the solver: pins.AddBatch(pinBatch); pinBatch.AddToSolver(pins); // override the pin indices with the ones we got at bind time: for (int i = 0; i < m_SolverIndices.Length; ++i) { pinBatch.particleIndices[i] = m_SolverIndices[i]; pinBatch.stiffnesses[i * 2] = m_Compliance; pinBatch.stiffnesses[i * 2 + 1] = constrainOrientation?0:10000; pinBatch.breakThresholds[i] = m_BreakThreshold; } // enable the batch: pinBatch.SetEnabled(true); } break; case AttachmentType.Static: for (int i = 0; i < m_SolverIndices.Length; ++i) { solver.invMasses[m_SolverIndices[i]] = 0; } if (m_Actor.usesOrientedParticles && m_ConstrainOrientation) { for (int i = 0; i < m_SolverIndices.Length; ++i) { solver.invRotationalMasses[m_SolverIndices[i]] = 0; } } m_Actor.UpdateParticleProperties(); break; } } }