Esempio n. 1
0
        /// <summary>
        /// Primarily final drawing, called late in the OnSceneGUI call
        /// </summary>
        private static void OnLateSceneGUI(SceneView sceneView)
        {
                        #if !NCAMERA
            return;
                                                #endif

            if (SceneView.lastActiveSceneView != sceneView)
            {
                return;
            }

            Event e = Event.current;

            if (e.type == EventType.Repaint)
            {
                OnRepaint(sceneView);
            }

            #region Axis Selectors

            if (cameraStatus == NCameraStatus.none || cameraStatus == NCameraStatus.off)
            {
                return;
            }

            if (!sceneView.in2DMode)
            {
                if (e.control && !e.alt)
                {
                    Action <Quaternion> Callback = q =>
                    {
                        Transform camTransform = sceneView.camera.transform;
                        sixAxisUp = q * Vector3.back;
                        sceneView.LookAt(sceneView.pivot, Quaternion.LookRotation(camTransform.forward, sixAxisUp));
                    };

                    AxisSelectorExtensions.AxisSelectorGUI(sceneView, sixAxisUp, Callback);
                }
            }

            if (!sceneView.in2DMode)
            {
                if (e.control && !e.alt)
                {
                    AxisSelectorExtensions.ShowOrHideOtherAxisSelectors(false);
                    axisSelectorsWereHidden = true;
                }
            }

            #endregion
        }
Esempio n. 2
0
        /// <summary>
        /// Primarily input operations, called early in the OnSceneGUI call
        /// </summary>
        private static void OnEarlySceneGUI(SceneView sceneView)
        {
                        #if !NCAMERA
            return;
                        #endif

            Event e = Event.current;

            if (e.type == EventType.Repaint)
            {
                repaintDeltaTime = Math.Min(0.1, EditorApplication.timeSinceStartup - lastRepaintTime);
                lastRepaintTime  = EditorApplication.timeSinceStartup;
            }

            if (cameraStatus == NCameraStatus.off)
            {
                if (e.type == EventType.Repaint)
                {
                    /*Rotate cameras back to normal if toggled off*/
                    Vector3 up  = sceneView.rotation * Vector3.up;
                    Vector3 fwd = sceneView.rotation * Vector3.forward;
                    //The Y component of camera-right
                    float crossYAbs = Mathf.Abs(up.z * fwd.x - up.x * fwd.z);                     //Vector3.Cross(up, fwd).y
                    if (crossYAbs > 0.01f)
                    {
                        sceneView.rotation = Quaternion.RotateTowards(sceneView.rotation,
                                                                      Quaternion.LookRotation(sceneView.rotation * Vector3.forward, Vector3.up), (float)repaintDeltaTime * axisSpeed);
                        doRepaintScene = true;
                    }
                    else if (crossYAbs > 0.001)
                    {
                        sceneView.rotation = Quaternion.LookRotation(sceneView.rotation * Vector3.forward, Vector3.up);
                        cameraStatus       = NCameraStatus.none;
                    }
                }
            }

            OnMouseAction(sceneView, e);             //This used to be wrapped in a if(e.isMouse), but this causes issues with capturing events outside of the window.
            if (e.isKey)
            {
                OnKeyboardAction(e);
            }

            if (cameraStatus == NCameraStatus.none || cameraStatus == NCameraStatus.none)
            {
                return;
            }

            if (axisSelectorsWereHidden)
            {
                AxisSelectorExtensions.ShowOrHideOtherAxisSelectors(true);
                axisSelectorsWereHidden = false;
            }

            if (e.type == EventType.Repaint)
            {
                //Enable Fly-cam support
                if (rightMouseIsDown)
                {
                    if (!altDown && (wDown || sDown || dDown || aDown || qDown || eDown))
                    {
                        Transform cameraTransform = sceneView.camera.transform;
                        sceneView.pivot += cameraTransform.forward *
                                           ((BoolToInt(wDown) - BoolToInt(sDown)) * (float)repaintDeltaTime * flyCamSensitivity);
                        sceneView.pivot += cameraTransform.right *
                                           ((BoolToInt(dDown) - BoolToInt(aDown)) * (float)repaintDeltaTime * flyCamSensitivity);
                        sceneView.pivot +=
                            cameraTransform.up * ((BoolToInt(eDown) - BoolToInt(qDown)) * (float)repaintDeltaTime * flyCamSensitivity);
                    }
                }

                //If we're in six-axis mode we should rotate back to Y-up regardless of whether the mouse is being interacted with or not.
                if (cameraStatus == NCameraStatus.sixAxis && !sceneViewAnimatedRot(sceneView).isAnimating)
                {
                    if (alignCameraAutomatically)
                    {
                        Vector3 fwd            = sceneView.rotation * Vector3.forward;
                        Vector3 right          = sceneView.rotation * Vector3.right;
                        Vector3 sixAxisUpOrtho = sixAxisUp;
                        Vector3.OrthoNormalize(ref fwd, ref sixAxisUpOrtho);
                        float dotAbs = Mathf.Abs(Vector3.Dot(right, sixAxisUpOrtho));
                        if (dotAbs > 0.01f)
                        {
                            sceneView.rotation = Quaternion.RotateTowards(sceneView.rotation,
                                                                          Quaternion.LookRotation(sceneView.rotation * Vector3.forward, sixAxisUpOrtho),
                                                                          (float)repaintDeltaTime * axisSpeed);
                            doRepaintScene = true;
                        }
                        else if (dotAbs > 0.001f)
                        {
                            sceneView.rotation = Quaternion.LookRotation(sceneView.rotation * Vector3.forward, sixAxisUpOrtho);
                        }
                    }
                }
            }
        }