protected override void OnDetach()
        {
            if (NativeCollisionObject == null)
            {
                return;
            }

            Simulation.RemoveCollider(this);

            base.OnDetach();
        }
예제 #2
0
        protected override void OnDetach()
        {
            Simulation.RemoveCollider(this);

            base.OnDetach();
        }
예제 #3
0
        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();
                }
            }
        }