Beispiel #1
0
        void SetGridEnabled(bool enable)
        {
            m_DrawGrid = enable;

            if (!m_DrawGrid)
            {
                GridRenderer.Destroy();
            }
            else
            {
                EditorUtility.SetUnityGridEnabled(false);
            }

            EditorPrefs.SetBool(PreferenceKeys.ShowGrid, enable);

            DoGridRepaint();
        }
Beispiel #2
0
        void DrawSceneGrid(SceneView view)
        {
            var currentEvent = Event.current;

            if (m_DrawGrid && (currentEvent.type == EventType.Repaint || m_DoGridRepaint))
            {
                Vector3 previousPivot = m_Pivot;
                CalculateGridPlacement(view);

                if (gridIsOrthographic)
                {
                    Axis camAxis = EnumExtension.AxisWithVector(Camera.current.transform.TransformDirection(Vector3.forward).normalized);
                    if (m_RenderPlane != camAxis)
                    {
                        SetRenderPlane(camAxis);
                    }
                    GridRenderer.DrawOrthographic(view.camera, camAxis, SnapValueInUnityUnits, m_DrawAngles ? AngleValue : -1f);
                }
                else
                {
                    float camDistance = Vector3.Distance(view.camera.transform.position, previousPivot);

                    if (m_DoGridRepaint ||
                        m_Pivot != previousPivot ||
                        Mathf.Abs(camDistance - m_LastDistanceCameraToPivot) > m_LastDistanceCameraToPivot / 2 ||
                        m_CameraDirection != m_PreviousCameraDirection)
                    {
                        m_PreviousCameraDirection   = m_CameraDirection;
                        m_DoGridRepaint             = false;
                        m_LastDistanceCameraToPivot = camDistance;

                        if (FullGridEnabled)
                        {
                            GridRenderer.SetPerspective3D(view.camera, m_Pivot, m_SnapSettings.SnapValueInUnityUnits());
                        }
                        else
                        {
                            m_PlaneGridDrawDistance = GridRenderer.SetPerspective(view.camera, m_RenderPlane, m_SnapSettings.SnapValueInUnityUnits(), m_Pivot, GridRenderOffset);
                        }
                    }

                    GridRenderer.Repaint();
                }
            }
        }
Beispiel #3
0
        internal static float SetPerspective(Camera cam, Axis axis, float snapValue, Vector3 position, float offset)
        {
            if ((axis & Axis.X) == Axis.X)
            {
                return(GridRenderer.SetPerspective(cam, position + Vector3.right * offset, Vector3.up, Vector3.forward, snapValue, gridColorX));
            }

            if ((axis & Axis.Y) == Axis.Y)
            {
                return(GridRenderer.SetPerspective(cam, position + Vector3.up * offset, Vector3.right, Vector3.forward, snapValue, gridColorY));
            }

            if ((axis & Axis.Z) == Axis.Z)
            {
                return(GridRenderer.SetPerspective(cam, position + Vector3.forward * offset, Vector3.up, Vector3.right, snapValue, gridColorZ));
            }

            return(0f);
        }
Beispiel #4
0
        public static void SetPreferences()
        {
            EditorPrefs.SetString(PreferenceKeys.GridColorX, JsonUtility.ToJson(s_GridColorX));
            EditorPrefs.SetString(PreferenceKeys.GridColorY, JsonUtility.ToJson(s_GridColorY));
            EditorPrefs.SetString(PreferenceKeys.GridColorZ, JsonUtility.ToJson(s_GridColorZ));
            EditorPrefs.SetFloat(PreferenceKeys.AlphaBump, s_AlphaBump);
            EditorPrefs.SetFloat(PreferenceKeys.BracketIncreaseValue, s_BracketIncreaseValue);
            EditorPrefs.SetInt(PreferenceKeys.GridUnit, (int)s_GridUnits);
            EditorPrefs.SetBool(PreferenceKeys.SyncUnitySnap, s_SyncUnitySnap);
            EditorPrefs.SetInt(PreferenceKeys.IncreaseGridSize, (int)s_IncreaseGridSize);
            EditorPrefs.SetInt(PreferenceKeys.DecreaseGridSize, (int)s_DecreaseGridSize);
            EditorPrefs.SetInt(PreferenceKeys.NudgePerspectiveBackward, (int)s_NudgePerspectiveBackward);
            EditorPrefs.SetInt(PreferenceKeys.NudgePerspectiveForward, (int)s_NudgePerspectiveForward);
            EditorPrefs.SetInt(PreferenceKeys.ResetGridShortcutModifiers, (int)s_NudgePerspectiveReset);
            EditorPrefs.SetInt(PreferenceKeys.CyclePerspective, (int)s_CyclePerspective);
            EditorPrefs.SetInt(PreferenceKeys.SnapMethod, (int)s_SnapMethod);

            if (ProGridsEditor.Instance != null)
            {
                GridRenderer.LoadPreferences();
                ProGridsEditor.Instance.LoadPreferences();
                ProGridsEditor.DoGridRepaint();
            }
        }