Ejemplo n.º 1
0
        /// <summary>
        /// Rotates the camera based on user input.
        /// </summary>
        private void RotateCameraBasedOnUserInput()
        {
            // Only rotate if the right mouse button is pressed
            if (_mouse.IsRightMouseButtonDown && _mouse.WasMouseMovedSinceLastFrame)
            {
                // Make sure all coroutines are stopped to avoid any conflicts
                StopAllCoroutines();

                // Calculate the amount of rotation which must be applied
                float rotationSpeedTimesDeltaTime = _rotationSpeedInDegrees * Time.deltaTime;

                // Rotate based on the type of rotation we are dealing with.
                // Note: Even if the rotation mode is set to orbit, we will still perform a 'LookAround' rotation
                //       if the camera hasn't been focused.
                if (_rotationMode == EditorCameraRotationMode.LookAround || !_wasFocused)
                {
                    EditorCameraRotation.RotateCamera(_camera,
                                                      -_mouse.CursorOffsetSinceLastFrame.y * rotationSpeedTimesDeltaTime,
                                                      _mouse.CursorOffsetSinceLastFrame.x * rotationSpeedTimesDeltaTime);
                }
                else
                if (_wasFocused && _rotationMode == EditorCameraRotationMode.Orbit)
                {
                    // Calculate the orbit point. This is done by moving from the camera position along the camera
                    // look vector by a distance equal to '_orbitOffsetAlongLook'.
                    Transform cameraTransform = _camera.transform;
                    Vector3   orbitPoint      = cameraTransform.position + cameraTransform.forward * _orbitOffsetAlongLook;

                    EditorCameraOrbit.OrbitCamera(_camera,
                                                  -_mouse.CursorOffsetSinceLastFrame.y * rotationSpeedTimesDeltaTime,
                                                  _mouse.CursorOffsetSinceLastFrame.x * rotationSpeedTimesDeltaTime, orbitPoint);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Rotates the camera based on user input.
        /// </summary>
        private void RotateCameraBasedOnUserInput()
        {
            // If no mouse movemenet was performed, we don't need to continue
            if (!_mouse.WasMouseMovedSinceLastFrame)
            {
                return;
            }

            bool orbit      = _cameraOrbitShortcut.IsActive();
            bool lookAround = !orbit && _cameraLookAroundShortcut.IsActive();

            if (orbit || lookAround)
            {
                // Make sure all coroutines are stopped to avoid any conflicts
                StopAllCoroutines();

                // Rotate based on the type of rotation we are dealing with.
                // Note: Even if the rotation mode is set to orbit, we will still perform a 'LookAround' rotation
                //       if the camera hasn't been focused.
                if (lookAround || !_wasFocused)
                {
                    float mouseX = Input.GetAxis("Mouse X");
                    float mouseY = Input.GetAxis("Mouse Y");
                    EditorCameraRotation.RotateCamera(Camera,
                                                      -mouseY * _rotationSpeedInDegrees,
                                                      mouseX * _rotationSpeedInDegrees);
                }
                else
                if (_wasFocused && orbit)
                {
                    float mouseX = Input.GetAxis("Mouse X");
                    float mouseY = Input.GetAxis("Mouse Y");

                    // Calculate the orbit point. This is done by moving from the camera position along the camera
                    // look vector by a distance equal to '_orbitOffsetAlongLook'.
                    Transform cameraTransform = Camera.transform;
                    Vector3   orbitPoint      = cameraTransform.position + cameraTransform.forward * _orbitOffsetAlongLook;

                    EditorCameraOrbit.OrbitCamera(Camera,
                                                  -mouseY * _rotationSpeedInDegrees,
                                                  mouseX * _rotationSpeedInDegrees, orbitPoint);
                }
            }
        }
        /// <summary>
        /// Rotates the camera based on user input.
        /// </summary>
        private void RotateCameraBasedOnUserInput()
        {
            // If no mouse movemenet was performed, we don't need to continue
            if (!_mouse.WasMouseMovedSinceLastFrame)
            {
                return;
            }

            //added by me
            if (WereAnyUIElementsHovered())
            {
                return;
            }
            bool orbit         = _cameraOrbitShortcut.IsActive() || toolBarController.isOrbiting;
            bool orbitSelected = toolBarController.isOrbitingSelected;
            //
            //bool orbit = _cameraOrbitShortcut.IsActive();
            bool lookAround = !orbit && _cameraLookAroundShortcut.IsActive();

            //if (orbit || lookAround)
            //added by me
            if (orbit || lookAround || orbitSelected)
            //
            {
                // Make sure all coroutines are stopped to avoid any conflicts
                StopAllCoroutines();

                // Calculate the amount of rotation which must be applied
                float rotationSpeedTimesDeltaTime = _rotationSpeedInDegrees * Time.deltaTime;

                // Rotate based on the type of rotation we are dealing with.
                // Note: Even if the rotation mode is set to orbit, we will still perform a 'LookAround' rotation
                //       if the camera hasn't been focused.
                //added by me
                if (orbitSelected)  //围绕选中物体旋转
                {
                    Transform cameraTransform = Camera.transform;

                    EditorCameraOrbit.OrbitCameraBaseOnSelected(Camera,
                                                                -_mouse.CursorOffsetSinceLastFrame.y * rotationSpeedTimesDeltaTime,
                                                                _mouse.CursorOffsetSinceLastFrame.x * rotationSpeedTimesDeltaTime, EditorCameraFocus.GetFocusOperationInfo(Camera, _focusSettings).FocusPoint);
                }
                else
                //
                if (lookAround || !_wasFocused)
                {
                    EditorCameraRotation.RotateCamera(Camera,
                                                      -_mouse.CursorOffsetSinceLastFrame.y * rotationSpeedTimesDeltaTime,
                                                      _mouse.CursorOffsetSinceLastFrame.x * rotationSpeedTimesDeltaTime);
                }
                else
                if (_wasFocused && orbit)
                {
                    // Calculate the orbit point. This is done by moving from the camera position along the camera
                    // look vector by a distance equal to '_orbitOffsetAlongLook'.
                    Transform cameraTransform = Camera.transform;
                    Vector3   orbitPoint      = cameraTransform.position + cameraTransform.forward * _orbitOffsetAlongLook;

                    EditorCameraOrbit.OrbitCamera(Camera,
                                                  -_mouse.CursorOffsetSinceLastFrame.y * rotationSpeedTimesDeltaTime,
                                                  _mouse.CursorOffsetSinceLastFrame.x * rotationSpeedTimesDeltaTime, orbitPoint);
                }
            }
        }