Esempio n. 1
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();
                }
            }
        }
Esempio n. 2
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);
        }