Ejemplo n.º 1
0
    // Removes the given rigid body from the world and cleans up after it.
    protected void DestroyRigidBody(CollisionObject obj)
    {
        RigidBody body = obj as RigidBody;

        if (body != null && body.MotionState != null)
        {
            body.MotionState.Dispose();
        }
        m_world.RemoveCollisionObject(obj);
        obj.Dispose();
    }
    void OnDestroy()
    {
        for (int i = 0; i < createdObjs.Count; i++)
        {
            Destroy(createdObjs[i]);
        }
        createdObjs.Clear();
        UnityEngine.Debug.Log("ExitPhysics");
        if (World != null)
        {
            //remove/dispose constraints
            int i;
            for (i = World.NumConstraints - 1; i >= 0; i--)
            {
                TypedConstraint constraint = World.GetConstraint(i);
                World.RemoveConstraint(constraint);
                constraint.Dispose();
            }

            //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)
                {
                    body.MotionState.Dispose();
                }
                World.RemoveCollisionObject(obj);
                obj.Dispose();
            }

            //delete collision shapes
            foreach (CollisionShape shape in CollisionShapes)
            {
                shape.Dispose();
            }
            CollisionShapes.Clear();

            World.Dispose();
            Broadphase.Dispose();
            Dispatcher.Dispose();
            CollisionConf.Dispose();
        }

        if (Broadphase != null)
        {
            Broadphase.Dispose();
        }
        if (Dispatcher != null)
        {
            Dispatcher.Dispose();
        }
        if (CollisionConf != null)
        {
            CollisionConf.Dispose();
        }
    }
Ejemplo n.º 3
0
        protected override void TraverseBeforeRemovedAction(Block entity)
        {
            base.TraverseBeforeRemovedAction(entity);

            if (EntityInfo.ContainsKey(entity))
            {
                _world.RemoveCollisionObject(EntityInfo[entity].Body);
                _world.UpdateAabbs();
            }
        }
Ejemplo n.º 4
0
        public virtual void ExitPhysics()
        {
            BulletExampleRunner.Get().ExitPhysics();
            UnityEngine.Debug.Log("ExitPhysics");
            if (_world != null)
            {
                //remove/dispose constraints
                int i;
                for (i = _world.NumConstraints - 1; i >= 0; i--)
                {
                    TypedConstraint constraint = _world.GetConstraint(i);
                    _world.RemoveConstraint(constraint);
                    constraint.Dispose();
                }

                //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)
                    {
                        body.MotionState.Dispose();
                    }
                    _world.RemoveCollisionObject(obj);
                    obj.Dispose();
                }

                //delete collision shapes
                foreach (CollisionShape shape in CollisionShapes)
                {
                    shape.Dispose();
                }
                CollisionShapes.Clear();

                _world.Dispose();
                Broadphase.Dispose();
                Dispatcher.Dispose();
                CollisionConf.Dispose();
            }

            if (Broadphase != null)
            {
                Broadphase.Dispose();
            }
            if (Dispatcher != null)
            {
                Dispatcher.Dispose();
            }
            if (CollisionConf != null)
            {
                CollisionConf.Dispose();
            }
        }
Ejemplo n.º 5
0
        public void Dispose()
        {
            if (_shootBoxShape != null)
            {
                var objects = _world.CollisionObjectArray
                              .Where(o => o.CollisionShape == _shootBoxShape);
                foreach (var obj in objects)
                {
                    _world.RemoveCollisionObject(obj);
                    obj.Dispose();
                }

                _shootBoxShape.Dispose();
                _shootBoxShape = null;
            }
        }
Ejemplo n.º 6
0
        public void ExitPhysics()
        {
            //remove/dispose constraints
            int i;

            for (i = World.NumConstraints - 1; i >= 0; i--)
            {
                TypedConstraint constraint = World.GetConstraint(i);
                World.RemoveConstraint(constraint);
                constraint.Dispose();;
            }

            //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)
                {
                    body.MotionState.Dispose();
                }
                World.RemoveCollisionObject(obj);
                obj.Dispose();
            }

            //delete collision shapes
            foreach (CollisionShape shape in CollisionShapes)
            {
                shape.Dispose();
            }
            CollisionShapes.Clear();

            World.Dispose();
            Broadphase.Dispose();
            if (Dispatcher != null)
            {
                Dispatcher.Dispose();
            }
        }
        private static void CleanupBodiesAndShapes(DynamicsWorld world)
        {
            var shapes = new HashSet <CollisionShape>();

            for (int i = world.NumCollisionObjects - 1; i >= 0; i--)
            {
                CollisionObject obj  = world.CollisionObjectArray[i];
                var             body = obj as RigidBody;
                if (body != null && body.MotionState != null)
                {
                    body.MotionState.Dispose();
                }
                world.RemoveCollisionObject(obj);
                GetShapeWithChildShapes(obj.CollisionShape, shapes);

                obj.Dispose();
            }

            foreach (var shape in shapes)
            {
                shape.Dispose();
            }
        }