public bool RemoveAction(IAction action) { if (!isDisposed) { if (physicWorldParameters.worldType < WorldType.RigidBodyDynamics) { Debug.LogError("World type must not be collision only"); } else { DDWorld.RemoveAction(action); return(true); } } return(false); }
private void Dispose(bool disposing) { if (physicWorldParameters.debugType >= BDebug.DebugType.Debug) { Debug.Log("BDynamicsWorld Disposing physics."); } if (_world != null) { //remove/dispose constraints int i; if (DDWorld != null) { if (physicWorldParameters.debugType >= BDebug.DebugType.Debug) { Debug.LogFormat("Removing Constraints {0}", DDWorld.NumConstraints); } for (i = DDWorld.NumConstraints - 1; i >= 0; i--) { TypedConstraint constraint = DDWorld.GetConstraint(i); DDWorld.RemoveConstraint(constraint); if (constraint.Userobject is BTypedConstraint) { ((BTypedConstraint)constraint.Userobject).m_isInWorld = false; } if (physicWorldParameters.debugType >= BDebug.DebugType.Debug) { Debug.LogFormat("Removed Constaint {0}", constraint.Userobject); } constraint.Dispose(); } } if (physicWorldParameters.debugType >= BDebug.DebugType.Debug) { Debug.LogFormat("Removing Collision Objects {0}", DDWorld.NumCollisionObjects); } //Remove the rigidbodies from the dynamics world and delete them for (i = _world.NumCollisionObjects - 1; i >= 0; i--) { CollisionObject obj = _world.CollisionObjectArray[i]; RigidBody body = obj as RigidBody; if (body != null && body.MotionState != null) { Debug.Assert(body.NumConstraintRefs == 0, "Rigid body still had constraints"); body.MotionState.Dispose(); } _world.RemoveCollisionObject(obj); if (obj.UserObject is BCollisionObject) { ((BCollisionObject)obj.UserObject).isInWorld = false; } if (physicWorldParameters.debugType >= BDebug.DebugType.Debug) { Debug.LogFormat("Removed CollisionObject {0}", obj.UserObject); } obj.Dispose(); } if (_world.DebugDrawer != null && _world.DebugDrawer is IDisposable) { ((IDisposable)_world.DebugDrawer).Dispose(); } _world.Dispose(); World = null; } if (broadphase != null) { broadphase.Dispose(); broadphase = null; } if (dispatcher != null) { dispatcher.Dispose(); dispatcher = null; } if (collisionConf != null) { collisionConf.Dispose(); collisionConf = null; } if (constraintSolver != null) { constraintSolver.Dispose(); constraintSolver = null; } if (ghostPairCallback != null) { ghostPairCallback.Dispose(); ghostPairCallback = null; } isDisposed = true; }