Beispiel #1
0
    void GetSelectionArea()
    {
        if (!mouseOverGameElements())
        {
            return;
        }

        // If we press the left mouse button, save mouse location and begin selection
        if (KeyActiveChecker.isActive(GameControlsManager.leftClickDown))
        {
            startedBoxSelection           = true;
            isBoxSelecting                = true;
            mousePositionAtSelectionStart = Input.mousePosition;
        }

        if (isBoxSelecting && KeyActiveChecker.isActive(GameControlsManager.leftClick))
        {
            mousePositionAtSelectionEnd = Input.mousePosition;
        }

        // If we let go of the left mouse button, end selection
        if (KeyActiveChecker.isActive(GameControlsManager.leftClickUp))
        {
            isBoxSelecting = false;
        }
    }
Beispiel #2
0
    void Update()
    {
        region = gameSession.getRegion();

        cameraMoving   = false;
        cameraRotating = false;
        cameraZooming  = false;

        if (toggleCenterPointFocus && !centeringOnPlayer)
        {
            toggleCenterPointFocus = false;
            centeringOnPlayer      = true;
            StartCoroutine(startCenteringOnPlayer());
        }

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

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

        viewCenterPoint = cameraPos + cameraDir * viewCenterOffset;

        checkInputConfiguration();

        float modifier = KeyActiveChecker.isActive(GameControlsManager.cameraSpeedModifier) ? cameraSpeedModifierMultiplier : 1f;

        Vector3 positionDelta = processCameraMovement() * modifier;
        Vector3 rotationDelta = processCameraRotation() * modifier;
        float   fovDelta      = processCameraZoom() * modifier;

        processCameraDeltas(positionDelta, rotationDelta, fovDelta);

        RestrictCamera();
    }
Beispiel #3
0
    private Vector3 processCameraRotation()
    {
        Vector3 rotation = Vector3.zero;

        if (allowMouseRotation && KeyActiveChecker.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);
    }
Beispiel #4
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;
        }

        // on right click
        if (KeyActiveChecker.isActive(GameControlsManager.rightClickDown))
        {
            mousePositionAtRightClickDown = Input.mousePosition;
        }

        // on middle click
        if (KeyActiveChecker.isActive(GameControlsManager.middleClickDown))
        {
            mousePositionAtMiddleClickDown = Input.mousePosition;
        }
    }
Beispiel #5
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;

        if (KeyActiveChecker.isActive(GameControlsManager.cameraForward) ||
            (allowEdgeScrolling && Input.mousePosition.y >= Screen.height - edgeScrollDetectBorderThickness))
        {
            positionDelta += forward;
        }
        if (KeyActiveChecker.isActive(GameControlsManager.cameraBack) ||
            (allowEdgeScrolling && Input.mousePosition.y <= edgeScrollDetectBorderThickness))
        {
            positionDelta -= forward;
        }
        if (KeyActiveChecker.isActive(GameControlsManager.cameraLeft) ||
            (allowEdgeScrolling && Input.mousePosition.x <= edgeScrollDetectBorderThickness))
        {
            positionDelta -= right;
        }
        if (KeyActiveChecker.isActive(GameControlsManager.cameraRight) ||
            (allowEdgeScrolling && Input.mousePosition.x >= Screen.width - edgeScrollDetectBorderThickness))
        {
            positionDelta += right;
        }
        if (KeyActiveChecker.isActive(GameControlsManager.cameraDown))
        {
            positionDelta += Vector3.down;
        }
        if (KeyActiveChecker.isActive(GameControlsManager.cameraUp))
        {
            positionDelta += Vector3.up;
        }

        // scrolling with mouse
        if (allowMouseTranslation && KeyActiveChecker.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);
    }