protected override void OnDetach() { foreach (var c in LinkedConstraints) { Simulation.RemoveConstraint(c); c.Dispose(); } Simulation.RemoveRigidBody(this); base.OnDetach(); }
protected override void OnDetach() { if (NativeCollisionObject == null) { return; } foreach (var c in LinkedConstraints) { Simulation.RemoveConstraint(c); c.Dispose(); } Simulation.RemoveRigidBody(this); base.OnDetach(); }
private void DeleteElement(PhysicsElementBase element) { element.Data = null; //might be possible that this element was not valid during creation so it would be already null if (element.InternalCollider == null) { return; } var toDispose = new List <IDisposable>(); elements.Remove(element); if (element.BoneIndex != -1) { boneElements.Remove((PhysicsSkinnedElementBase)element); } switch (element.Type) { case PhysicsElementBase.Types.PhantomCollider: case PhysicsElementBase.Types.StaticCollider: { simulation.RemoveCollider(element.Collider); } break; case PhysicsElementBase.Types.StaticRigidBody: case PhysicsElementBase.Types.DynamicRigidBody: case PhysicsElementBase.Types.KinematicRigidBody: { var rb = (RigidBody)element.Collider; var constraints = rb.LinkedConstraints.ToArray(); foreach (var c in constraints) { simulation.RemoveConstraint(c); toDispose.Add(c); } simulation.RemoveRigidBody(rb); } break; case PhysicsElementBase.Types.CharacterController: { characters.Remove(element); simulation.RemoveCharacter((Character)element.Collider); } break; } toDispose.Add(element.Collider); if (element.ColliderShape != null && !element.ColliderShape.IsPartOfAsset) { toDispose.Add(element.ColliderShape); } element.Collider = null; //dispose in another thread for better performance //if (!now) //{ // TaskList.Dispatch(toDispose, 4, 128, (i, disposable) => disposable.Dispose()); //} //else { foreach (var d in toDispose) { d.Dispose(); } } }