示例#1
0
        private void InitCameraPixelRect()
        {
            Rect rect = m_viewport.Camera.pixelRect;

            m_camPixelRect = rect;

            if (!m_gameState.IsMenuOpened(LocalPlayerIndex) && !m_gameState.IsActionsMenuOpened(LocalPlayerIndex) && !m_gameState.IsContextActionInProgress(LocalPlayerIndex))
            {
                VirtualMousePosition = m_camPixelRect.center;
            }
        }
 private void OnActionsMenu(int playerIndex)
 {
     if (!m_gameState.IsActionsMenuOpened(playerIndex))
     {
         if (IsAutoCommandsOpen)
         {
             IsAutoCommandsOpen = false;
         }
         else if (IsOpen)
         {
             IsOpen = false;
         }
     }
 }
示例#3
0
        private void Update()
        {
            //if (m_gameState.IsContextActionInProgress(LocalPlayerIndex))
            //{
            //    return;
            //}
            if (m_gameState.IsPauseStateChanging)
            {
                return;
            }



            if (m_inputManager.GetButtonDown(InputAction.Back, LocalPlayerIndex, false, false))
            {
                if (m_gameState.IsContextActionInProgress(LocalPlayerIndex))
                {
                    m_gameState.IsContextActionInProgress(LocalPlayerIndex, false);
                    return;
                }

                if (!m_gameState.IsActionsMenuOpened(LocalPlayerIndex))
                {
                    m_gameState.IsMenuOpened(LocalPlayerIndex, !m_gameState.IsMenuOpened(LocalPlayerIndex));
                    m_menuPanel.SetIsOpened(!m_menuPanel.IsOpened);
                }
            }

            if (m_gameState.IsMenuOpened(LocalPlayerIndex))
            {
                if (m_inputManager.GetButtonDown(InputAction.B, LocalPlayerIndex, true, false))
                {
                    if (m_menuPanel.IsOpened)
                    {
                        m_gameState.IsMenuOpened(LocalPlayerIndex, false);
                    }
                    m_menuPanel.SetIsOpened(false);
                    m_consolePanel.SetIsOpened(false);
                    m_settingsPanel.SetIsOpened(false);
                    m_resultsPanel.SetIsOpened(false);
                }
            }
        }
示例#4
0
        private void Update()
        {
            if (m_gameState.IsActionsMenuOpened(LocalPlayerIndex))
            {
                if (!m_cameraController.IsInputEnabled)
                {
                    m_cameraController.IsInputEnabled = true;
                }
                return;
            }

            if (m_gameState.IsMenuOpened(LocalPlayerIndex))
            {
                if (!m_cameraController.IsInputEnabled)
                {
                    m_cameraController.IsInputEnabled = true;
                }
                return;
            }

            if (m_gameState.IsContextActionInProgress(LocalPlayerIndex))
            {
                if (!m_cameraController.IsInputEnabled)
                {
                    m_cameraController.IsInputEnabled = true;
                }
                return;
            }

            if (m_gameState.IsPaused || m_gameState.IsPauseStateChanging)
            {
                return;
            }

            if (m_gameState.IsReplay)
            {
                return;
            }

            int playerIndex = PlayerIndex;

            m_selectInterval   -= Time.deltaTime;
            m_unselectInterval -= Time.deltaTime;

            bool multiselect = m_inputManager.GetButton(InputAction.RB, LocalPlayerIndex);

            if (m_inputManager.GetButtonDown(InputAction.LMB, LocalPlayerIndex))
            {
                RaycastHit hitInfo;
                if (Physics.Raycast(m_cameraController.Ray, out hitInfo))
                {
                    Voxel voxel = hitInfo.transform.GetComponentInParent <Voxel>();
                    if (voxel != null)
                    {
                        VoxelData data = voxel.VoxelData;
                        if (VoxelData.IsControllableUnit(data.Type) && data.Owner == playerIndex)
                        {
                            m_unitSelection.ClearSelection(playerIndex);
                            m_unitSelection.Select(playerIndex, playerIndex, new[] { data.UnitOrAssetIndex });
                        }
                        else
                        {
                            m_unitSelection.ClearSelection(playerIndex);
                        }
                    }
                    else
                    {
                        m_unitSelection.ClearSelection(playerIndex);
                    }
                }
                else
                {
                    m_unitSelection.ClearSelection(playerIndex);
                }

                if (m_boxSelector != null)
                {
                    m_boxSelector.Activate();
                }
            }

            if (m_inputManager.GetButtonDown(InputAction.LB, LocalPlayerIndex))
            {
                bool select = true;

                if (multiselect)
                {
                    long[] units     = m_gameState.GetUnits(playerIndex).ToArray();
                    long   unitIndex = GetAt(units, m_cameraController.MapCursor);

                    if (m_unitSelection.IsSelected(playerIndex, playerIndex, unitIndex))
                    {
                        m_unitSelection.Unselect(playerIndex, playerIndex, new[] { unitIndex });
                        m_wasSelected.Remove(unitIndex);
                        select = false;
                    }
                }

                if (select)
                {
                    Select(playerIndex, multiselect);
                    m_selectInterval   = 0.3f;
                    m_unselectInterval = float.PositiveInfinity;
                    m_multiselectMode  = true;
                }
                else
                {
                    m_selectInterval   = float.PositiveInfinity;
                    m_unselectInterval = 0.3f;
                }
            }
            else if (m_inputManager.GetButton(InputAction.LB, LocalPlayerIndex))
            {
                if (m_selectInterval <= 0)
                {
                    Select(playerIndex, multiselect);
                    m_selectInterval = 0.2f;
                }

                if (m_unselectInterval <= 0)
                {
                    Unselect(playerIndex);
                    m_unselectInterval = 0.2f;
                }

                m_cameraController.IsInputEnabled = false;
            }
            else if (m_inputManager.GetButtonUp(InputAction.LB, LocalPlayerIndex, false, false))
            {
                m_cameraController.IsInputEnabled = true;
            }

            if (m_inputManager.GetButtonDown(InputAction.RB, LocalPlayerIndex))
            {
                m_multiselectMode = false;
            }
            else if (m_inputManager.GetButtonUp(InputAction.RB, LocalPlayerIndex))
            {
                if (!m_multiselectMode)
                {
                    if (!m_targetSelection.HasSelected(playerIndex))
                    {
                        m_wasSelected.Clear();
                        m_unitSelection.ClearSelection(playerIndex);
                    }
                }
            }
        }
        private void Update()
        {
            if (m_gameState.IsActionsMenuOpened(LocalPlayerIndex))
            {
                return;
            }

            if (m_gameState.IsMenuOpened(LocalPlayerIndex))
            {
                return;
            }

            if (m_gameState.IsContextActionInProgress(LocalPlayerIndex))
            {
                return;
            }

            if (m_gameState.IsPaused || m_gameState.IsPauseStateChanging)
            {
                return;
            }

            int playerIndex = PlayerIndex;

            if (m_mapCursor != m_cameraController.MapCursor)
            {
                m_mapCursor = m_cameraController.MapCursor;


                VoxelData newSelectedTarget = null;
                VoxelData target            = null;
                int       width             = m_map.Map.GetMapSizeWith(GameConstants.MinVoxelActorWeight);
                if (m_mapCursor.Row >= 0 && m_mapCursor.Col >= 0 && m_mapCursor.Row < width && m_mapCursor.Col < width)
                {
                    MapCell cell = m_map.Map.Get(m_mapCursor.Row, m_mapCursor.Col, m_cameraController.Weight);

                    for (int i = 0; i < m_selectedUnitDescriptors.Length; ++i)
                    {
                        SelectionDescriptor descriptor = m_selectedUnitDescriptors[i];
                        bool lowestPossible            = true;
                        cell.GetDefaultTargetFor(descriptor.Type, descriptor.Weight, playerIndex, lowestPossible, out target, playerIndex);
                        if (target != null)
                        {
                            break;
                        }
                    }
                }

                if (target != null && target.VoxelRef != null && target.UnitOrAssetIndex != -1)
                {
                    //Player could not destroy own units (and should not be able to select them as target)
                    if (!VoxelData.IsControllableUnit(target.Type) || target.Owner != playerIndex)
                    {
                        newSelectedTarget = target;
                    }
                }

                if (m_previouslySelected != newSelectedTarget)
                {
                    if (newSelectedTarget == null)
                    {
                        ClearSelection();
                        m_selectedTarget     = null;
                        m_previouslySelected = null;
                    }
                    else
                    {
                        m_previouslySelected = newSelectedTarget;
                        TryEnableTargetAutoSelectionMode();
                        if (m_isTargetAutoSelectionMode)
                        {
                            m_selectedTarget = newSelectedTarget;
                            TargetSelectionSelect(playerIndex, target.Owner, m_selectedTarget.UnitOrAssetIndex);
                        }
                    }
                }
            }
            else
            {
                if (m_selectedTarget != null)
                {
                    IVoxelDataController dc = m_gameState.GetVoxelDataController(m_selectedTarget.Owner, m_selectedTarget.UnitOrAssetIndex);
                    if (dc != null && dc.IsAlive)
                    {
                        Coordinate cursorCoord = new Coordinate(m_cameraController.MapCursor, GameConstants.MinVoxelActorWeight, 0).ToWeight(dc.ControlledData.Weight);
                        if (cursorCoord.MapPos != dc.Coordinate.MapPos)
                        {
                            Coordinate coord = dc.Coordinate.ToWeight(GameConstants.MinVoxelActorWeight);
                            m_cameraController.MapPivot = coord.MapPos;
                            m_cameraController.SetVirtualMousePosition(coord, true, false);
                            m_mapCursor = m_cameraController.MapCursor;
                        }
                    }
                }
            }

            if (m_inputManager.GetButtonDown(InputAction.X, LocalPlayerIndex))
            {
                bool hasSelected = m_targetSelection.HasSelected(playerIndex);

                Select(playerIndex);

                if (!hasSelected)
                {
                    m_isTargetAutoSelectionMode = true;
                }
            }
            else if (m_inputManager.GetButtonUp(InputAction.RB, LocalPlayerIndex))
            {
                m_isTargetAutoSelectionMode = false;

                ClearSelection();
            }
        }
        private void Update()
        {
            if (m_gameState.IsActionsMenuOpened(m_viewport.LocalPlayerIndex))
            {
                return;
            }

            if (m_gameState.IsMenuOpened(m_viewport.LocalPlayerIndex))
            {
                return;
            }

            if (m_gameState.IsPaused || m_gameState.IsPauseStateChanging)
            {
                return;
            }

            Transform camTransform = m_viewport.Camera.transform;

            if (camTransform.position != m_prevCamPos || camTransform.rotation != m_prevCamRot)
            {
                m_prevCamPos = camTransform.position;
                m_prevCamRot = camTransform.rotation;

                float angle = camTransform.eulerAngles.y;
                m_rtMapBounds.rotation = Quaternion.Euler(new Vector3(0, 0, angle));

                ProjectCamera(m_rtMapBounds.rotation);
            }

            if (m_input.GetButtonDown(InputAction.Start, m_viewport.LocalPlayerIndex, false, false))
            {
                m_gotFocus = !m_gotFocus;
                if (m_gotFocus)
                {
                    m_eventSystem.SetSelectedGameObjectOnLateUpdate(m_selectableMinimap.gameObject);
                }
                else
                {
                    m_cameraController.CenterVirtualMouse();
                    m_eventSystem.SetSelectedGameObjectOnLateUpdate(null);
                }
            }

            if (m_input.GetButtonDown(InputAction.LMB, m_viewport.LocalPlayerIndex, false, false))
            {
                Vector2 pt;
                if (RectTransformUtility.ScreenPointToLocalPointInRectangle((RectTransform)m_rtMapBounds.parent, m_cameraController.VirtualMousePosition, null, out pt))
                {
                    float normalizedDistance = pt.magnitude / m_rootRadius;
                    if (normalizedDistance <= 1)
                    {
                        m_mouseManipulation   = true;
                        m_virtualMousePostion = m_cameraController.VirtualMousePosition;
                        Move(camTransform, true, 0, 0, 0, 0);
                    }
                }
            }
            else if (m_input.GetButtonUp(InputAction.LMB, m_viewport.LocalPlayerIndex, false, false))
            {
                m_mouseManipulation = false;
            }

            if (m_gotFocus || m_input.GetButton(InputAction.LB, m_viewport.LocalPlayerIndex, false, false) && IsCursorInMinimapBounds())
            {
                if (m_input.GetButtonDown(InputAction.B, m_viewport.LocalPlayerIndex, false, false))
                {
                    m_gotFocus = false;
                    m_cameraController.CenterVirtualMouse();
                    m_eventSystem.SetSelectedGameObjectOnLateUpdate(null);
                }
                else if (m_input.GetButtonDown(InputAction.LB, m_viewport.LocalPlayerIndex, false, false))
                {
                    m_virtualMousePostion = m_cameraController.VirtualMousePosition;
                    Move(camTransform, true, 0, 0, 0, 0);
                }
                else
                {
                    bool aPressed         = m_input.GetButton(InputAction.A, m_viewport.LocalPlayerIndex, false, false);
                    bool pivotPreciseMode = aPressed | m_input.GetButton(InputAction.RightStickButton, m_viewport.LocalPlayerIndex, false, false);

                    float pivotMultiplier = 1;
                    if (!pivotPreciseMode)
                    {
                        pivotMultiplier = 5;
                    }

                    float deltaY = m_input.GetAxisRaw(InputAction.MoveForward, m_viewport.LocalPlayerIndex, false, false) * Time.deltaTime * m_camCtrlSettings.MoveSensitivity * pivotMultiplier;
                    float deltaX = m_input.GetAxisRaw(InputAction.MoveSide, m_viewport.LocalPlayerIndex, false, false) * Time.deltaTime * m_camCtrlSettings.MoveSensitivity * pivotMultiplier;

                    bool  cursorPreciseMode = aPressed | m_input.GetButton(InputAction.LeftStickButton, m_viewport.LocalPlayerIndex, false, false);
                    float cursorMultiplier  = 4;
                    if (!cursorPreciseMode)
                    {
                        cursorMultiplier = 12;
                    }
                    float cursorY = m_input.GetAxisRaw(InputAction.CursorY, m_viewport.LocalPlayerIndex, false, false) * Time.deltaTime * m_camCtrlSettings.CursorSensitivity * cursorMultiplier;
                    float cursorX = m_input.GetAxisRaw(InputAction.CursorX, m_viewport.LocalPlayerIndex, false, false) * Time.deltaTime * m_camCtrlSettings.CursorSensitivity * cursorMultiplier;

                    Move(camTransform, false, deltaY, deltaX, cursorY, cursorX);
                }
            }

            if (m_mouseManipulation)
            {
                if (m_input.GetButton(InputAction.LMB, m_viewport.LocalPlayerIndex, false, false))
                {
                    float cursorMultiplier = 12;
                    float cursorY          = m_input.GetAxisRaw(InputAction.CursorY, m_viewport.LocalPlayerIndex, false, false) * Time.deltaTime * m_camCtrlSettings.CursorSensitivity * cursorMultiplier;
                    float cursorX          = m_input.GetAxisRaw(InputAction.CursorX, m_viewport.LocalPlayerIndex, false, false) * Time.deltaTime * m_camCtrlSettings.CursorSensitivity * cursorMultiplier;

                    Move(camTransform, false, cursorY, cursorX, 0, 0);
                }
            }
        }
        private void Update()
        {
            m_playersBot.Update(Time.realtimeSinceStartup);

            if (m_gameState.IsActionsMenuOpened(LocalPlayerIndex))
            {
                return;
            }

            if (m_gameState.IsContextActionInProgress(LocalPlayerIndex))
            {
                return;
            }

            if (m_gameState.IsMenuOpened(LocalPlayerIndex))
            {
                return;
            }

            if (m_gameState.IsPaused || m_gameState.IsPauseStateChanging)
            {
                return;
            }

            if (m_inputManager.GetButtonDown(InputAction.A, LocalPlayerIndex) || m_inputManager.GetButtonDown(InputAction.RMB, LocalPlayerIndex))
            {
                m_wasAButtonDown = true;

                CreateMovementCmd(false, cmd =>
                {
                    if (cmd != null && cmd.Count > 0)
                    {
                        MovementCmd movementCmd = (MovementCmd)cmd[0];

                        if (!m_inputManager.IsKeyboardAndMouse(LocalPlayerIndex))
                        {
                            m_cameraController.SetVirtualMousePosition(movementCmd.Coordinates.Last(), true, true);
                        }
                    }
                });
            }
            else if (m_inputManager.GetButtonUp(InputAction.A, LocalPlayerIndex) || m_inputManager.GetButtonUp(InputAction.RMB, LocalPlayerIndex))
            {
                if (m_wasAButtonDown)
                {
                    CreateMovementCmd(false, cmd =>
                    {
                        if (cmd != null && cmd.Count > 0)
                        {
                            MovementCmd movementCmd = (MovementCmd)cmd[0];
                            if (!m_inputManager.IsKeyboardAndMouse(LocalPlayerIndex))
                            {
                                m_cameraController.SetVirtualMousePosition(movementCmd.Coordinates.Last(), true, true);
                            }
                            SubmitToEngine(m_gameState.LocalToPlayerIndex(LocalPlayerIndex), cmd);
                        }
                    });
                    m_wasAButtonDown = false;
                }
            }
            else if (m_inputManager.GetButtonDown(InputAction.B, LocalPlayerIndex, false, false))
            {
                OnCancel();
            }
            else if (m_inputManager.GetButtonDown(InputAction.Y, LocalPlayerIndex, false, false))
            {
                m_commandsPanel.IsOpen = true;
            }
        }