Example #1
0
        private void ProcessControls()
        {
            KeyActiveManager.Update(); // process key presses

            if (KeyActiveManager.IsActive(GameControlsManager.LeftClickDown))
            {
                OnMouse0Down();
            }

            if (KeyActiveManager.IsActive(GameControlsManager.LeftClick))
            {
                OnMouse0Hold();
            }

            if (KeyActiveManager.IsActive(GameControlsManager.LeftClickUp))
            {
                OnMouse0Up();
            }

            if (KeyActiveManager.IsActive(GameControlsManager.RightClickDown))
            {
                OnMouse1Down();
            }

            if (KeyActiveManager.IsActive(GameControlsManager.AgentStopHotkey))
            {
                OrderStopSelectedAgents();
            }
        }
Example #2
0
        private void CheckInputConfiguration()
        {
            _mouseOverGame = false;
            // mouse cursor position check
            if (Input.mousePosition.x >= 0 &&
                Input.mousePosition.y >= 0 &&
                Input.mousePosition.x <= Screen.width &&
                Input.mousePosition.y <= Screen.height)
            {
                _mouseOverGame = true;
            }

            _mouseOverGame &= !_gameControl.IsMouseOverUi();

            // on right click
            if (KeyActiveManager.IsActive(GameControlsManager.RightClickDown))
            {
                _mousePositionAtRightClickDown = Input.mousePosition;
            }

            // on middle click
            if (KeyActiveManager.IsActive(GameControlsManager.MiddleClickDown))
            {
                _mousePositionAtMiddleClickDown = Input.mousePosition;
            }
        }
Example #3
0
        void Update()
        {
            _cameraMoving   = false;
            _cameraRotating = false;
            _cameraZooming  = false;

            Vector3 cameraPos = this.transform.position,
                    cameraDir = this.transform.forward;

            cameraPos.y = 0;
            cameraDir.y = 0;

            _viewCenterPoint = cameraPos + cameraDir * viewCenterOffset;

            CheckInputConfiguration();

            float modifier = KeyActiveManager.IsActive(GameControlsManager.CameraSpeedModifier)
                ? cameraSpeedModifierMultiplier
                : 1f;

            Vector3 positionDelta = ProcessCameraMovement() * modifier;
            Vector3 rotationDelta = ProcessCameraRotation() * modifier;
            float   fovDelta      = ProcessCameraZoom() * modifier;

            ProcessCameraDeltas(positionDelta, rotationDelta, fovDelta);

            RestrictCamera();
        }
Example #4
0
 private void SelectionStart()
 {
     if (KeyActiveManager.IsActive(GameControlsManager.LeftClickDown))
     {
         _startedBoxSelection           = true;
         _isBoxSelecting                = true;
         _mousePositionAtSelectionStart = Input.mousePosition;
         SelectionManager.Dirty         = true;
     }
 }
Example #5
0
        private Vector3 ProcessCameraRotation()
        {
            Vector3 rotation = Vector3.zero;

            if (allowMouseRotation && KeyActiveManager.IsActive(GameControlsManager.RightClick)) // right mouse
            {
                if (_mouseOverGame)
                {
                    Vector3 mouseDelta = Input.mousePosition - _mousePositionAtRightClickDown;

                    rotation += Vector3.up * mouseDelta.x / Screen.width;    // horizontal
                    rotation += Vector3.left * mouseDelta.y / Screen.height; // vertical

                    rotation *= mouseRotationSensitivityModifier * globalSensitivity * Time.deltaTime;

                    if (Vector3.zero != rotation)
                    {
                        _cameraRotating = true;
                    }
                }
            }

            return(rotation);
        }
Example #6
0
        // keyboard and edge scrolling
        private Vector3 ProcessCameraMovement()
        {
            Vector3 positionDelta = Vector3.zero;

            Vector3 mouseDelta = Input.mousePosition - _mousePositionAtMiddleClickDown;
            Vector3 forward    = transform.forward;
            Vector3 right      = transform.right;

            forward.y = 0;
            right.y   = 0;

            forward.Normalize();
            right.Normalize();

            if (KeyActiveManager.IsActive(GameControlsManager.CameraForward) ||
                (allowEdgeScrolling && Input.mousePosition.y >= Screen.height - edgeScrollDetectBorderThickness))
            {
                positionDelta += forward;
            }

            if (KeyActiveManager.IsActive(GameControlsManager.CameraBack) ||
                (allowEdgeScrolling && Input.mousePosition.y <= edgeScrollDetectBorderThickness))
            {
                positionDelta -= forward;
            }

            if (KeyActiveManager.IsActive(GameControlsManager.CameraLeft) ||
                (allowEdgeScrolling && Input.mousePosition.x <= edgeScrollDetectBorderThickness))
            {
                positionDelta -= right;
            }

            if (KeyActiveManager.IsActive(GameControlsManager.CameraRight) ||
                (allowEdgeScrolling && Input.mousePosition.x >= Screen.width - edgeScrollDetectBorderThickness))
            {
                positionDelta += right;
            }

            if (KeyActiveManager.IsActive(GameControlsManager.CameraDown))
            {
                positionDelta += Vector3.down;
            }

            if (KeyActiveManager.IsActive(GameControlsManager.CameraUp))
            {
                positionDelta += Vector3.up;
            }

            // scrolling with mouse
            if (allowMouseTranslation && KeyActiveManager.IsActive(GameControlsManager.MiddleClick))
            {
                if (_mouseOverGame)
                {
                    Vector3 mouseTranslation = Vector3.zero;
                    mouseTranslation += right * mouseDelta.x / Screen.width;
                    mouseTranslation += forward * mouseDelta.y / Screen.height;

                    positionDelta += mouseTranslation * mouseTranslationSensitivityModifier;
                }
            }

            positionDelta *= scrollingSensitivityModifier * globalSensitivity * Time.deltaTime;

            if (Vector3.zero != positionDelta)
            {
                _cameraMoving = true;
            }

            return(positionDelta);
        }