コード例 #1
0
        private void RevealEntity(IMyEntity entity)
        {
            if (entity != entity.GetTopMostParent())
            {
                return;
            }

            entity.GetStorage().SetValue(Id, "False");
            MyGamePruningStructure.Add((MyEntity)entity);
            entity.Physics?.Activate();
            RegisterRecursive(entity);

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

                foreach (var child in e.Hierarchy.Children)
                {
                    RegisterRecursive(child.Container.Entity);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Reveals this group to game and physics logic.
        /// </summary>
        public void Reveal()
        {
            foreach (var entity in Grids)
            {
                if (entity.Parent == null)
                {
                    MyGamePruningStructure.Add(entity);
                }
            }

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

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

                foreach (var child in e.Hierarchy.Children)
                {
                    RegisterRecursive(child.Container.Entity);
                }
            }
        }
コード例 #3
0
        // Try to perform the grouping operation
        private void PerformGrouping()
        {
            if (ControlledEntity == null)
            {
                return;
            }

            var groupWithEntity = PickEntity();

            if (groupWithEntity != null)
            {
                DisablePicking = true;
                // Create a confirmation dialog for grouping and group items together
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(buttonType: MyMessageBoxButtonsType.YES_NO,
                                                                     messageText:
                                                                     new StringBuilder("Do you want to put " + ControlledEntity.DisplayName +
                                                                                       " under hierarchy of " + groupWithEntity.DisplayName + "?"),
                                                                     messageCaption: new StringBuilder("Hierarchy Group"), callback: @enum =>
                {
                    if (@enum == MyGuiScreenMessageBox.ResultEnum.YES)
                    {
                        // This causes the entity to get removed from Pruning structure
                        MyEntities.Remove(ControlledEntity);
                        // Entity would get added to pruning structure but does not because Parent != null
                        groupWithEntity.Hierarchy.AddChild(ControlledEntity, true);
                    }

                    DisablePicking = false;
                }));
            }
            else
            {
                DisablePicking = true;
                // Create a confirmation dialog for grouping and group items together
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(buttonType: MyMessageBoxButtonsType.YES_NO,
                                                                     messageText:
                                                                     new StringBuilder("Do you want to Remove the " + ControlledEntity.DisplayName +
                                                                                       " from the hierarchy?"),
                                                                     messageCaption: new StringBuilder("Hierarchy Ungroup"), callback: @enum =>
                {
                    if (@enum == MyGuiScreenMessageBox.ResultEnum.YES)
                    {
                        ControlledEntity.Parent.Hierarchy.RemoveChild(ControlledEntity, true);
                        // Needs to be added back
                        MyEntities.Add(ControlledEntity);
                        MyGamePruningStructure.Add(ControlledEntity);
                        Operation = m_previousOperation;
                    }

                    DisablePicking = false;
                }));
            }
        }
コード例 #4
0
ファイル: ConcealGroup.cs プロジェクト: jimmble/Concealment
        /// <summary>
        /// Reveals this group to game and physics logic.
        /// </summary>
        public void Reveal()
        {
            foreach (var entity in Grids)
            {
                if (entity.Parent == null)
                {
                    MyGamePruningStructure.Add(entity);
                }
            }


            var weldGroups = new HashSet <MyGroups <MyEntity, MyWeldGroupData> .Group>();

            foreach (var body in Grids)
            {
                if (body.Physics == null)
                {
                    continue;
                }
                var group = MyWeldingGroups.Static.GetGroup(body);
                if (group == null)
                {
                    body.Physics.Activate();
                }
                else
                {
                    weldGroups.Add(group);
                }
            }
            foreach (var group in weldGroups)
            {
                var body = group.GroupData.Parent;
                if (!(body.Physics is MyPhysicsBody bodyPhysics))
                {
                    continue;
                }
                bodyPhysics.Activate();

                foreach (var child in group.Nodes)
                {
                    if (child.NodeData != body &&
                        !child.NodeData.MarkedForClose &&
                        child.NodeData.Physics is MyPhysicsBody physBody)
                    {
                        bodyPhysics.Weld(physBody);
                    }
                }

                body.RaisePhysicsChanged();
            }


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

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

                foreach (var child in e.Hierarchy.Children)
                {
                    RegisterRecursive(child.Container.Entity);
                }
            }
        }
コード例 #5
0
ファイル: ConcealGroup.cs プロジェクト: franky500/Concealment
        /// <summary>
        /// Reveals this group to game and physics logic.
        /// </summary>
        public void Reveal()
        {
            foreach (var entity in Grids)
            {
                if (entity.Parent == null)
                {
                    MyGamePruningStructure.Add(entity);
                }
            }


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

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

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

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

            void ActivateRigidBody(MyCubeGrid grid, HkWorld world, HkRigidBody body)
            {
                if (body == null)
                {
                    return;
                }

                // make it dynamic
                if (body.GetMotionType() != HkMotionType.Dynamic && !grid.IsStatic)
                {
                    body.UpdateMotionType(HkMotionType.Dynamic);
                }

                // wake it up
                body.Activate();
                // restore velocity?
            }
        }