private void ConcealEntity(IMyEntity entity)
        {
            if (entity != entity.GetTopMostParent())
            {
                return;
            }

            entity.GetStorage().SetValue(Id, "True");
            MyGamePruningStructure.Remove((MyEntity)entity);
            entity.Physics?.Deactivate();
            UnregisterRecursive(entity);

            void UnregisterRecursive(IMyEntity e)
            {
                MyEntities.UnregisterForUpdate((MyEntity)e);
                if (e.Hierarchy == null)
                {
                    return;
                }

                foreach (var child in e.Hierarchy.Children)
                {
                    UnregisterRecursive(child.Container.Entity);
                }
            }
        }
        /// <summary>
        /// Conceals this group from game and physics logic.
        /// </summary>
        public void Conceal()
        {
            foreach (var body in Grids)
            {
                if (body.Parent == null)
                {
                    UnregisterRecursive(body);
                }
            }

            foreach (var entity in Grids)
            {
                if (entity.Parent == null)
                {
                    MyGamePruningStructure.Remove(entity);
                }
            }

            void UnregisterRecursive(IMyEntity e)
            {
                MyEntities.UnregisterForUpdate((MyEntity)e);
                (e.GameLogic as IMyGameLogicComponent)?.UnregisterForUpdate();
                if (e.Hierarchy == null)
                {
                    return;
                }

                foreach (var child in e.Hierarchy.Children)
                {
                    UnregisterRecursive(child.Container.Entity);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Conceals this group from game and physics logic.
        /// </summary>
        public void Conceal()
        {
            foreach (var body in Grids)
            {
                if (body.Parent == null)
                {
                    UnregisterRecursive(body);
                }
            }

            foreach (var body in Grids)
            {
                body.Physics?.UnweldAll(false);
            }
            foreach (var body in Grids)
            {
                body.Physics?.Deactivate();
            }

            foreach (var entity in Grids)
            {
                if (entity.Parent == null)
                {
                    MyGamePruningStructure.Remove(entity);
                }
            }

            void UnregisterRecursive(IMyEntity e)
            {
                MyEntities.UnregisterForUpdate((MyEntity)e);
                if (e.Hierarchy == null)
                {
                    return;
                }

                foreach (var child in e.Hierarchy.Children)
                {
                    UnregisterRecursive(child.Container.Entity);
                }
            }
        }
        /// <summary>
        /// Conceals this group from game and physics logic.
        /// </summary>
        public void Conceal()
        {
            foreach (var body in Grids)
            {
                if (body.Parent == null)
                {
                    UnregisterRecursive(body);
                }
            }

            foreach (var body in Grids)
            {
                var world = body.Physics?.HavokWorld;
                if (world == null || body.Physics.IsWelded)
                {
                    continue;
                }
                try
                {
                    world.LockCriticalOperations();
                    foreach (var constraint in body.Physics.Constraints)
                    {
                        if (MyPhysicsBody.IsConstraintValid(constraint))
                        {
                            world.RemoveConstraint(constraint);
                        }
                    }
                    DeactivateRigidBody(body, world, body.Physics.RigidBody);
                    DeactivateRigidBody(body, world, body.Physics.RigidBody2);
                }
                finally
                {
                    world.UnlockCriticalOperations();
                }
            }

            foreach (var entity in Grids)
            {
                if (entity.Parent == null)
                {
                    MyGamePruningStructure.Remove(entity);
                }
            }

            void DeactivateRigidBody(MyCubeGrid grid, HkWorld world, HkRigidBody body)
            {
                if (world == null || body == null)
                {
                    return;
                }
                // stop it
                body.LinearVelocity  = Vector3.Zero;
                body.AngularVelocity = Vector3.Zero;
                // put it to sleep
                body.Deactivate();
                // make it static
                if (body.GetMotionType() != HkMotionType.Fixed)
                {
                    body.UpdateMotionType(HkMotionType.Fixed);
                }
                // Remove from collision
                // Cache velocity?
            }

            void UnregisterRecursive(IMyEntity e)
            {
                MyEntities.UnregisterForUpdate((MyEntity)e);
                if (e.Hierarchy == null)
                {
                    return;
                }

                foreach (var child in e.Hierarchy.Children)
                {
                    UnregisterRecursive(child.Container.Entity);
                }
            }
        }