/// <summary>
        /// Starts a smooth zoom operation.
        /// </summary>
        private IEnumerator StartSmoothZoom()
        {
            // Calculate the camera initial speed and the smooth value based on the camera type
            float currentSpeed = (Camera.orthographic ? _zoomSettings.OrthographicSmoothZoomSpeed : _zoomSettings.PerspectiveSmoothZoomSpeed) * Input.GetAxis("Mouse ScrollWheel");
            float smoothValue  = Camera.orthographic ? _zoomSettings.OrthographicSmoothValue : _zoomSettings.PerspectiveSmoothValue;

            currentSpeed *= CalculateZoomFactor();

            while (true)
            {
                // Zoom the camera using the current speed
                float zoomAmount = currentSpeed * Time.deltaTime;
                EditorCameraZoom.ZoomCamera(Camera, zoomAmount);
                SetOrthoSize(Camera.orthographicSize); // Ugly, ugly, ugly!!!!

                // Move from the current speed towards 0 using the smooth value
                currentSpeed = Mathf.Lerp(currentSpeed, 0.0f, smoothValue);

                _orbitOffsetAlongLook -= zoomAmount;
                if (_orbitOffsetAlongLook < 0.0f)
                {
                    _orbitOffsetAlongLook = 1e-5f;
                }

                // Exit if the speed is small enough
                if (Mathf.Abs(currentSpeed) < 1e-5f)
                {
                    break;
                }

                // Wait for the next frame
                yield return(null);
            }
        }
Example #2
0
        /// <summary>
        /// Starts a smooth zoom operation.
        /// </summary>
        private IEnumerator StartSmoothZoom()
        {
            // Calculate the camera initial speed and the smooth value based on the camera type
            float currentSpeed = (_camera.orthographic ? _zoomSettings.OrthographicSmoothZoomSpeed : _zoomSettings.PerspectiveSmoothZoomSpeed) * Input.GetAxis("Mouse ScrollWheel");
            float smoothValue  = _camera.orthographic ? _zoomSettings.OrthographicSmoothValue : _zoomSettings.PerspectiveSmoothValue;

            if (TakeZoomFactorIntoAccount)
            {
                currentSpeed *= CalculateZoomFactor();
            }

            while (true)
            {
                // Zoom the camera using the current speed
                EditorCameraZoom.ZoomCamera(_camera, currentSpeed * Time.deltaTime);

                // Move from the current speed towards 0 using the smooth value
                currentSpeed = Mathf.Lerp(currentSpeed, 0.0f, smoothValue);

                // Exit if the speed is small enough
                if (Mathf.Abs(currentSpeed) < 1e-5f)
                {
                    break;
                }

                // Wait for the next frame
                yield return(null);
            }
        }
Example #3
0
        /// <summary>
        /// Applies any necessary zoom to the camera based on user input.
        /// </summary>
        private void ApplyCameraZoomBasedOnUserInput()
        {
            // Zoom if necessary
            float scrollSpeed = Input.GetAxis("Mouse ScrollWheel");

            if (scrollSpeed != 0.0f)
            {
                // Make sure all coroutines are stopped to avoid any conflicts
                StopAllCoroutines();

                // Zoom based on the active zoom mode
                if (_zoomSettings.ZoomMode == EditorCameraZoomMode.Standard)
                {
                    // Note: We will use the mouse scroll wheel for zooming and we will establish
                    //       the zoom speed based on the camera type.
                    float zoomSpeed = _camera.orthographic ? _zoomSettings.OrthographicStandardZoomSpeed : _zoomSettings.PerspectiveStandardZoomSpeed * Time.deltaTime;
                    if (TakeZoomFactorIntoAccount)
                    {
                        zoomSpeed *= CalculateZoomFactor();
                    }
                    EditorCameraZoom.ZoomCamera(_camera, scrollSpeed * zoomSpeed);
                }
                else
                {
                    StopAllCoroutines();
                    StartCoroutine("StartSmoothZoom");
                }
            }
        }
Example #4
0
        /// <summary>
        /// Applies any necessary zoom to the camera based on user input.
        /// </summary>
        private void ApplyCameraZoomBasedOnUserInput()
        {
            // Ugly, ugly, ugly!!!
            if (RuntimeEditorApplication.Instance.ScrollGridUpDownShortcut.IsActive() ||
                RuntimeEditorApplication.Instance.ScrollGridUpDownStepShortcut.IsActive())
            {
                return;
            }

            // Zoom if necessary
            float scrollSpeed = Input.GetAxis("Mouse ScrollWheel");

            if (scrollSpeed != 0.0f)
            {
                // Make sure all coroutines are stopped to avoid any conflicts
                StopAllCoroutines();

                // Zoom based on the active zoom mode
                if (_zoomSettings.ZoomMode == EditorCameraZoomMode.Standard)
                {
                    // Note: We will use the mouse scroll wheel for zooming and we will establish
                    //       the zoom speed based on the camera type.
                    float zoomSpeed = Camera.orthographic ? _zoomSettings.OrthographicStandardZoomSpeed : _zoomSettings.PerspectiveStandardZoomSpeed * Time.deltaTime;
                    zoomSpeed *= CalculateZoomFactor();
                    EditorCameraZoom.ZoomCamera(Camera, scrollSpeed * zoomSpeed);

                    SetOrthoSize(Camera.orthographicSize); // Ugly, ugly, ugly!!!!
                }
                else
                {
                    StopAllCoroutines();
                    StartCoroutine("StartSmoothZoom");
                }
            }
        }
        /// <summary>
        /// Moves the camera based on user supplied input.
        /// </summary>
        private void MoveCameraBasedOnUserInput()
        {
            //added by me
            if (WereAnyUIElementsHovered())
            {
                return;
            }
            //
            float moveAmount = _moveSettings.MoveSpeed * Time.deltaTime;

            moveAmount *= CalculateZoomFactor();

            Transform cameraTransform = Camera.transform;

            if (_moveForwardShortcut.IsActive())
            {
                if (Camera.orthographic)
                {
                    EditorCameraZoom.ZoomCamera(Camera, moveAmount);
                }
                else
                {
                    cameraTransform.position += cameraTransform.forward * moveAmount;
                }
            }
            else
            if (_moveBackShortcut.IsActive())
            {
                if (Camera.orthographic)
                {
                    EditorCameraZoom.ZoomCamera(Camera, -moveAmount);
                }
                else
                {
                    cameraTransform.position -= cameraTransform.forward * moveAmount;
                }
            }

            if (_strafeLeftShortcut.IsActive())
            {
                cameraTransform.position -= cameraTransform.right * moveAmount;
            }
            else if (_strafeRightShortcut.IsActive())
            {
                cameraTransform.position += cameraTransform.right * moveAmount;
            }

            if (_moveDownShortcut.IsActive())
            {
                cameraTransform.position -= cameraTransform.up * moveAmount;
            }
            else if (_moveUpShortcut.IsActive())
            {
                cameraTransform.position += cameraTransform.up * moveAmount;
            }

            SetOrthoSize(Camera.orthographicSize); // Ugly, ugly, ugly!!!!
        }
Example #6
0
        /// <summary>
        /// Moves the camera based on user supplied input.
        /// </summary>
        private void MoveCameraBasedOnUserInput()
        {
            if (_mouse.IsRightMouseButtonDown)
            {
                float moveAmount = _moveSettings.MoveSpeed * Time.deltaTime;
                if (TakeZoomFactorIntoAccount)
                {
                    moveAmount *= CalculateZoomFactor();
                }

                Transform cameraTransform = _camera.transform;
                if (Input.GetKey(KeyCode.W))
                {
                    if (_camera.orthographic)
                    {
                        EditorCameraZoom.ZoomCamera(_camera, moveAmount);
                    }
                    else
                    {
                        cameraTransform.position += cameraTransform.forward * moveAmount;
                    }
                }
                else
                if (Input.GetKey(KeyCode.S))
                {
                    if (_camera.orthographic)
                    {
                        EditorCameraZoom.ZoomCamera(_camera, -moveAmount);
                    }
                    else
                    {
                        cameraTransform.position -= cameraTransform.forward * moveAmount;
                    }
                }

                if (Input.GetKey(KeyCode.A))
                {
                    cameraTransform.position -= cameraTransform.right * moveAmount;
                }
                else if (Input.GetKey(KeyCode.D))
                {
                    cameraTransform.position += cameraTransform.right * moveAmount;
                }

                if (Input.GetKey(KeyCode.Q))
                {
                    cameraTransform.position -= cameraTransform.up * moveAmount;
                }
                else if (Input.GetKey(KeyCode.E))
                {
                    cameraTransform.position += cameraTransform.up * moveAmount;
                }
            }
        }
        /// <summary>
        /// Starts a smooth zoom operation.
        /// </summary>
        private IEnumerator StartSmoothZoom()
        {
            //added by me
            var scrollSpeed = Input.GetAxis("Mouse ScrollWheel");

            if (toolBarController.isZooming)
            {
                scrollSpeed += Input.GetAxis("Mouse Y");
            }
            float currentSpeed = (Camera.orthographic ? _zoomSettings.OrthographicSmoothZoomSpeed : _zoomSettings.PerspectiveSmoothZoomSpeed) * scrollSpeed;
            //
            // Calculate the camera initial speed and the smooth value based on the camera type
            //float currentSpeed = (Camera.orthographic ? _zoomSettings.OrthographicSmoothZoomSpeed : _zoomSettings.PerspectiveSmoothZoomSpeed) * Input.GetAxis("Mouse ScrollWheel");
            float smoothValue = Camera.orthographic ? _zoomSettings.OrthographicSmoothValue : _zoomSettings.PerspectiveSmoothValue;

            currentSpeed *= CalculateZoomFactor();

            while (true)
            {
                // Zoom the camera using the current speed
                EditorCameraZoom.ZoomCamera(Camera, currentSpeed * Time.deltaTime);
                SetOrthoSize(Camera.orthographicSize); // Ugly, ugly, ugly!!!!

                // Move from the current speed towards 0 using the smooth value
                currentSpeed = Mathf.Lerp(currentSpeed, 0.0f, smoothValue);

                // Exit if the speed is small enough
                if (Mathf.Abs(currentSpeed) < 1e-5f)
                {
                    break;
                }

                // Wait for the next frame
                yield return(null);
            }
        }
        /// <summary>
        /// Moves the camera based on user supplied input.
        /// </summary>
        private void MoveCameraBasedOnUserInput()
        {
            float moveAmount = _moveSettings.MoveSpeed * Time.deltaTime;

            moveAmount *= CalculateZoomFactor();

            Transform cameraTransform = Camera.transform;

            if (_moveForwardShortcut.IsActive())
            {
                if (Camera.orthographic)
                {
                    EditorCameraZoom.ZoomCamera(Camera, moveAmount);
                }
                else
                {
                    cameraTransform.position += cameraTransform.forward * moveAmount;
                }

                _orbitOffsetAlongLook -= moveAmount;
                if (_orbitOffsetAlongLook < 0.0f)
                {
                    _orbitOffsetAlongLook = 1e-5f;
                }
            }
            else
            if (_moveBackShortcut.IsActive())
            {
                if (Camera.orthographic)
                {
                    EditorCameraZoom.ZoomCamera(Camera, -moveAmount);
                }
                else
                {
                    cameraTransform.position -= cameraTransform.forward * moveAmount;
                }

                _orbitOffsetAlongLook += moveAmount;
                if (_orbitOffsetAlongLook < 0.0f)
                {
                    _orbitOffsetAlongLook = 1e-5f;
                }
            }

            if (_strafeLeftShortcut.IsActive())
            {
                cameraTransform.position -= cameraTransform.right * moveAmount;
            }
            else if (_strafeRightShortcut.IsActive())
            {
                cameraTransform.position += cameraTransform.right * moveAmount;
            }

            if (_moveDownShortcut.IsActive())
            {
                cameraTransform.position -= cameraTransform.up * moveAmount;
            }
            else if (_moveUpShortcut.IsActive())
            {
                cameraTransform.position += cameraTransform.up * moveAmount;
            }

            SetOrthoSize(Camera.orthographicSize); // Ugly, ugly, ugly!!!!
        }