示例#1
0
        private void OnGUI()
        {
            if (GameView.s_GizmoButtonStyle == null)
            {
                GameView.s_GizmoButtonStyle                 = "GV Gizmo DropDown";
                GameView.s_ResolutionWarningStyle           = new GUIStyle("PreOverlayLabel");
                GameView.s_ResolutionWarningStyle.alignment = TextAnchor.UpperLeft;
                GameView.s_ResolutionWarningStyle.padding   = new RectOffset(6, 6, 1, 1);
            }
            this.DoToolbarGUI();
            Rect gameViewRenderRect = this.gameViewRenderRect;
            bool fitsInsideRect;
            Rect constrainedGameViewRenderRect = GameView.GetConstrainedGameViewRenderRect(gameViewRenderRect, this.selectedSizeIndex, out fitsInsideRect);
            Rect rect = GUIClip.Unclip(constrainedGameViewRenderRect);

            base.SetInternalGameViewRect(rect);
            EditorGUIUtility.AddCursorRect(constrainedGameViewRenderRect, MouseCursor.CustomCursor);
            EventType type = Event.current.type;

            if (type == EventType.MouseDown && gameViewRenderRect.Contains(Event.current.mousePosition))
            {
                Unsupported.SetAllowCursorLock(true);
                Unsupported.SetAllowCursorHide(true);
            }
            else
            {
                if (type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape)
                {
                    Unsupported.SetAllowCursorLock(false);
                }
            }
            if (type == EventType.Repaint)
            {
                if (!this.currentGameViewSize.isFreeAspectRatio || !InternalEditorUtility.HasFullscreenCamera())
                {
                    GUI.Box(gameViewRenderRect, GUIContent.none, "GameViewBackground");
                }
                Vector2 s_EditorScreenPointOffset = GUIUtility.s_EditorScreenPointOffset;
                GUIUtility.s_EditorScreenPointOffset = Vector2.zero;
                SavedGUIState savedGUIState = SavedGUIState.Create();
                if (Display.MultiDisplayLicense())
                {
                    EditorGUIUtility.RenderGameViewCameras(rect, this.m_TargetDisplay, this.m_Gizmos, true);
                }
                else
                {
                    EditorGUIUtility.RenderGameViewCameras(rect, 0, this.m_Gizmos, true);
                }
                savedGUIState.ApplyAndForget();
                GUIUtility.s_EditorScreenPointOffset = s_EditorScreenPointOffset;
            }
            else
            {
                if (type != EventType.Layout && type != EventType.Used)
                {
                    if (WindowLayout.s_MaximizeKey.activated && (!EditorApplication.isPlaying || EditorApplication.isPaused))
                    {
                        return;
                    }
                    bool flag = constrainedGameViewRenderRect.Contains(Event.current.mousePosition);
                    if (Event.current.rawType == EventType.MouseDown && !flag)
                    {
                        return;
                    }
                    Event.current.mousePosition = new Vector2(Event.current.mousePosition.x - constrainedGameViewRenderRect.x, Event.current.mousePosition.y - constrainedGameViewRenderRect.y);
                    EditorGUIUtility.QueueGameViewInputEvent(Event.current);
                    bool flag2 = true;
                    if (Event.current.rawType == EventType.MouseUp && !flag)
                    {
                        flag2 = false;
                    }
                    if (type == EventType.ExecuteCommand || type == EventType.ValidateCommand)
                    {
                        flag2 = false;
                    }
                    if (flag2)
                    {
                        Event.current.Use();
                    }
                    else
                    {
                        Event.current.mousePosition = new Vector2(Event.current.mousePosition.x + constrainedGameViewRenderRect.x, Event.current.mousePosition.y + constrainedGameViewRenderRect.y);
                    }
                }
            }
            this.ShowResolutionWarning(new Rect(gameViewRenderRect.x, gameViewRenderRect.y, 200f, 20f), fitsInsideRect, constrainedGameViewRenderRect.size);
            if (this.m_Stats)
            {
                GameViewGUI.GameViewStatsGUI();
            }
        }
示例#2
0
 public static void RenderGameViewCameras(Rect cameraRect, Rect statsRect, bool gizmos, bool gui)
 {
     EditorGUIUtility.RenderGameViewCameras(cameraRect, 0, gizmos, gui);
 }
示例#3
0
        private void OnGUI()
        {
            bool flag;

            if (s_GizmoButtonStyle == null)
            {
                s_GizmoButtonStyle                 = "GV Gizmo DropDown";
                s_ResolutionWarningStyle           = new GUIStyle("PreOverlayLabel");
                s_ResolutionWarningStyle.alignment = TextAnchor.UpperLeft;
                s_ResolutionWarningStyle.padding   = new RectOffset(6, 6, 1, 1);
            }
            this.DoToolbarGUI();
            Rect gameViewRenderRect = this.gameViewRenderRect;
            Rect rect       = GetConstrainedGameViewRenderRect(EditorGUIUtility.PointsToPixels(gameViewRenderRect), this.selectedSizeIndex, out flag);
            Rect rect4      = EditorGUIUtility.PixelsToPoints(rect);
            Rect rect5      = GUIClip.Unclip(rect4);
            Rect cameraRect = EditorGUIUtility.PointsToPixels(rect5);

            base.SetInternalGameViewRect(rect5);
            EditorGUIUtility.AddCursorRect(rect4, MouseCursor.CustomCursor);
            EventType type = Event.current.type;

            if ((type == EventType.MouseDown) && gameViewRenderRect.Contains(Event.current.mousePosition))
            {
                this.AllowCursorLockAndHide(true);
            }
            else if ((type == EventType.KeyDown) && (Event.current.keyCode == KeyCode.Escape))
            {
                Unsupported.SetAllowCursorLock(false);
            }
            switch (type)
            {
            case EventType.Layout:
            case EventType.Used:
                break;

            case EventType.Repaint:
            {
                bool flag2 = EditorGUIUtility.IsDisplayReferencedByCameras(this.m_TargetDisplay);
                if ((!this.currentGameViewSize.isFreeAspectRatio || !InternalEditorUtility.HasFullscreenCamera()) || !flag2)
                {
                    GUI.Box(gameViewRenderRect, GUIContent.none, "GameViewBackground");
                    if (!flag2)
                    {
                        GUI.Label(new Rect((gameViewRenderRect.width / 2f) - 50f, (gameViewRenderRect.height / 2f) - 10f, 200f, 50f), "No camera");
                    }
                }
                Vector2 vector = GUIUtility.s_EditorScreenPointOffset;
                GUIUtility.s_EditorScreenPointOffset = Vector2.zero;
                SavedGUIState state = SavedGUIState.Create();
                if (this.ShouldShowMultiDisplayOption())
                {
                    EditorGUIUtility.RenderGameViewCameras(cameraRect, this.m_TargetDisplay, this.m_Gizmos, true);
                }
                else
                {
                    EditorGUIUtility.RenderGameViewCameras(cameraRect, 0, this.m_Gizmos, true);
                }
                GL.sRGBWrite = false;
                state.ApplyAndForget();
                GUIUtility.s_EditorScreenPointOffset = vector;
                break;
            }

            default:
            {
                if (WindowLayout.s_MaximizeKey.activated && (!EditorApplication.isPlaying || EditorApplication.isPaused))
                {
                    return;
                }
                bool flag3 = rect4.Contains(Event.current.mousePosition);
                if ((Event.current.rawType == EventType.MouseDown) && !flag3)
                {
                    return;
                }
                Vector2 mousePosition = Event.current.mousePosition;
                Vector2 position      = mousePosition - rect4.position;
                position = EditorGUIUtility.PointsToPixels(position);
                Event.current.mousePosition = position;
                EditorGUIUtility.QueueGameViewInputEvent(Event.current);
                bool flag4 = true;
                if ((Event.current.rawType == EventType.MouseUp) && !flag3)
                {
                    flag4 = false;
                }
                switch (type)
                {
                case EventType.ExecuteCommand:
                case EventType.ValidateCommand:
                    flag4 = false;
                    break;
                }
                if (flag4)
                {
                    Event.current.Use();
                }
                else
                {
                    Event.current.mousePosition = mousePosition;
                }
                break;
            }
            }
            this.ShowResolutionWarning(new Rect(gameViewRenderRect.x, gameViewRenderRect.y, 200f, 20f), flag, rect.size);
            if (this.m_Stats)
            {
                GameViewGUI.GameViewStatsGUI();
            }
        }