void OnSwitchNext()
        {
            var controlledIndex = m_entitiesGui.FindIndex(IsControlledEntity);

            if (controlledIndex != -1)
            {
                MyEntity oldControlledEntity = m_entitiesGui[controlledIndex].Entity;

                var index = controlledIndex;
                MyGuiControlEntityUse currentEntityControl = null;

                bool foundCandidate;

                do
                {
                    index++;
                    if (index >= m_entitiesGui.Count)
                    {
                        index = 0;
                    }
                    if (index == controlledIndex)
                    {
                        break;
                    }

                    currentEntityControl = m_entitiesGui[index];

                    foundCandidate =
                        (currentEntityControl is MyGuiControlPrefabCameraUse && oldControlledEntity is MyPrefabCamera ||
                         currentEntityControl is MyGuiControlPrefabLargeWeaponUse && oldControlledEntity is MyPrefabLargeWeapon
                        ) &&
                        currentEntityControl.Entity.Enabled &&
                        !currentEntityControl.Entity.Closed &&
                        !currentEntityControl.IsControlledByOtherPlayer();
                } while (!foundCandidate);

                if (index != controlledIndex && currentEntityControl != null)
                {
                    SwitchControlToEntity(oldControlledEntity, currentEntityControl.Entity);
                }
            }
        }
 bool IsControlledEntity(MyGuiControlEntityUse entityControl)
 {
     return(MyGuiScreenGamePlay.Static.ControlledEntity == entityControl.Entity);
 }
        public override void RecreateControls(bool contructor)
        {
            base.RecreateControls(contructor);

            Controls.Clear();

            m_entitiesGuiList = new MyGuiControlList(
                this,
                new Vector2(0.0034f, -0.030f),
                new Vector2(0.489f, 0.65f),
                Vector4.Zero,
                null,//MyTextsWrapper.Get(MyTextsWrapperEnum.SecurityControlHUB),
                MyGuiManager.GetBlankTexture(),
                new Vector2(0.01f, 0.0f));

            if (!contructor)
            {
                foreach (var entityGui in m_entitiesGui)
                {
                    entityGui.ClearAfterRemove();
                }
            }
            m_entitiesGui.Clear();
            foreach (IMyUseableEntity connectedEntity in m_prefabSecurityControlHUB.ConnectedEntities)
            {
                MyEntity entity = connectedEntity as MyEntity;

                if (!entity.Visible)
                {
                    continue;
                }
                Debug.Assert((connectedEntity.UseProperties.UseType & MyUseType.FromHUB) != 0);
                IMyHasGuiControl entityWithGuiControl = connectedEntity as IMyHasGuiControl;
                Debug.Assert(entityWithGuiControl != null);
                // if entity is not hacked and could be hacked from HUB, then try hack it
                if (!connectedEntity.UseProperties.IsHacked &&
                    (connectedEntity.UseProperties.HackType & MyUseType.FromHUB) != 0)
                {
                    if (m_useBy.HackingTool != null &&
                        m_useBy.HackingTool.HackingLevel >= connectedEntity.UseProperties.HackingLevel)
                    {
                        connectedEntity.UseProperties.IsHacked = true;
                    }
                }
                MyGuiControlEntityUse entityGui = entityWithGuiControl.GetGuiControl(m_entitiesGuiList);
                entityGui.ParentScreen = this;
                m_entitiesGui.Add(entityGui);
            }
            m_entitiesGuiList.InitControls(m_entitiesGui);
            Controls.Add(m_entitiesGuiList);

            var exitButton = new MyGuiControlButton(
                this,
                new Vector2(0f, 0.3740f),
                new Vector2(0.161f, 0.0637f),
                Vector4.One,
                MyGuiManager.GetConfirmButton(),
                null,
                null,
                MyTextsWrapperEnum.Exit,
                MyGuiConstants.BUTTON_TEXT_COLOR,
                MyGuiConstants.BUTTON_TEXT_SCALE,
                MyGuiControlButtonTextAlignment.CENTERED,
                OnExitClick,
                true,
                MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER,
                true,
                true);

            Controls.Add(exitButton);
        }