Example #1
0
        private static bool CanZoomToCursor(NCameraStatus status)
        {
            switch (status)
            {
            case NCameraStatus.sixAxis:
                return((zoomToCursor & ZoomToCursor.SixAxis) != 0);

            case NCameraStatus.trackball:
                return((zoomToCursor & ZoomToCursor.Trackball) != 0);

            default:
                return((zoomToCursor & ZoomToCursor.DefaultCamera) != 0);
            }
        }
Example #2
0
        private static void LoadSettings()
        {
            if (!EditorPrefs.HasKey("vertxCameraZoomToCursor"))
            {
                zoomToCursor = ZoomToCursor.SixAxis | ZoomToCursor.Trackball | ZoomToCursor.DefaultCamera;
            }
            else
            {
                zoomToCursor = (ZoomToCursor)EditorPrefs.GetInt("vertxCameraZoomToCursor");
            }

            if (!EditorPrefs.HasKey("vertxAlignCameraAutomatically"))
            {
                alignCameraAutomatically = true;
            }
            else
            {
                alignCameraAutomatically = EditorPrefs.GetBool("vertxAlignCameraAutomatically");
            }

            if (!EditorPrefs.HasKey("vertxZoomToCursorIgnoresBackfaces"))
            {
                zoomToCursorIgnoresBackfaces = true;
            }
            else
            {
                zoomToCursorIgnoresBackfaces = EditorPrefs.GetBool("vertxZoomToCursorIgnoresBackfaces");
            }

            cameraStatus = (NCameraStatus)EditorPrefs.GetInt("vertxCameraStatus");

            switch (cameraStatus)
            {
            case NCameraStatus.off:
            case NCameraStatus.none:
                material.mainTexture = textureDefault;
                break;

            case NCameraStatus.sixAxis:
                material.mainTexture = textureSixAxis;
                break;

            default:
                material.mainTexture = textureTrackball;
                break;
            }
        }
Example #3
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);
                        }
                    }
                }
            }
        }