SetAllowCursorLock() private method

private SetAllowCursorLock ( bool allow ) : void
allow bool
return void
示例#1
0
 private void OnLostFocus()
 {
     if (!EditorApplicationLayout.IsInitializingPlaymodeLayout())
     {
         Unsupported.SetAllowCursorLock(false);
         Unsupported.SetAllowCursorHide(false);
     }
     InternalEditorUtility.OnGameViewFocus(false);
 }
示例#2
0
        private void DragTitleBar(Rect titleBarRect)
        {
            int   id  = GUIUtility.GetControlID(FocusType.Passive);
            Event evt = Event.current;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.Repaint:
                EditorGUIUtility.AddCursorRect(titleBarRect, MouseCursor.Arrow);
                break;

            case EventType.MouseDown:
                // If the mouse is inside the title bar rect, we say that we're the hot control
                if (titleBarRect.Contains(evt.mousePosition) && GUIUtility.hotControl == 0 && evt.button == 0)
                {
                    GUIUtility.hotControl = id;
                    Event.current.Use();
                    s_LastDragMousePos = GUIUtility.GUIToScreenPoint(evt.mousePosition);
                    dragPosition       = position;
                    Unsupported.SetAllowCursorLock(false, Unsupported.DisallowCursorLockReasons.SizeMove);
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id)
                {
                    GUIUtility.hotControl = 0;
                    Event.current.Use();
                    Unsupported.SetAllowCursorLock(true, Unsupported.DisallowCursorLockReasons.SizeMove);
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    Vector2 absMouse = GUIUtility.GUIToScreenPoint(evt.mousePosition);
                    Vector2 movement = absMouse - s_LastDragMousePos;

                    float minimumDelta = 1.0f / GUIUtility.pixelsPerPoint;

                    if (Mathf.Abs(movement.x) >= minimumDelta || Mathf.Abs(movement.y) >= minimumDelta)
                    {
                        s_LastDragMousePos = absMouse;

                        dragPosition.x += movement.x;
                        dragPosition.y += movement.y;
                        position        = dragPosition;

                        GUI.changed = true;
                    }
                }
                break;
            }
        }
        private void DragTitleBar(Rect titleBarRect)
        {
            int   id  = GUIUtility.GetControlID(FocusType.Passive);
            Event evt = Event.current;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.Repaint:
                if (m_DraggingNativeTitleBarCaption)
                {
                    m_DraggingNativeTitleBarCaption = false;
                }
                EditorGUIUtility.AddCursorRect(titleBarRect, MouseCursor.Arrow);
                break;

            case EventType.MouseDown:
                // If the mouse is inside the title bar rect, we say that we're the hot control
                if (titleBarRect.Contains(evt.mousePosition) && GUIUtility.hotControl == 0 && evt.button == 0)
                {
                    if (Application.platform != RuntimePlatform.LinuxEditor)
                    {
                        Event.current.Use();
                        m_DraggingNativeTitleBarCaption = true;
                        SendCaptionEvent(m_DraggingNativeTitleBarCaption);
                    }
                    else
                    {
                        GUIUtility.hotControl = id;
                        Event.current.Use();
                        s_LastDragMousePos = evt.mousePosition;
                        startDragDpi       = GUIUtility.pixelsPerPoint;
                        Unsupported.SetAllowCursorLock(false, Unsupported.DisallowCursorLockReasons.SizeMove);
                    }
                }
                break;

            case EventType.MouseUp:
                if (m_DraggingNativeTitleBarCaption)
                {
                    break;
                }

                if (GUIUtility.hotControl == id)
                {
                    GUIUtility.hotControl = 0;
                    Event.current.Use();
                    Unsupported.SetAllowCursorLock(true, Unsupported.DisallowCursorLockReasons.SizeMove);
                }
                break;

            case EventType.MouseDrag:
                if (m_DraggingNativeTitleBarCaption)
                {
                    break;
                }

                if (GUIUtility.hotControl == id)
                {
                    Vector2 mousePos = evt.mousePosition;
                    if (startDragDpi != GUIUtility.pixelsPerPoint)
                    {
                        // We ignore this mouse event when changing screens in multi monitor setups with
                        // different dpi scalings as funky things might/will happen
                        startDragDpi       = GUIUtility.pixelsPerPoint;
                        s_LastDragMousePos = mousePos;
                    }
                    else
                    {
                        Vector2 movement = mousePos - s_LastDragMousePos;

                        float minimumDelta = 1.0f / GUIUtility.pixelsPerPoint;

                        if (Mathf.Abs(movement.x) >= minimumDelta || Mathf.Abs(movement.y) >= minimumDelta)
                        {
                            Rect dragPosition = position;
                            dragPosition.x += movement.x;
                            dragPosition.y += movement.y;
                            position        = dragPosition;

                            GUI.changed = true;
                        }
                    }
                }
                break;
            }
        }
示例#4
0
 protected void AllowCursorLockAndHide(bool enable)
 {
     Unsupported.SetAllowCursorLock(enable, Unsupported.DisallowCursorLockReasons.Other);
     Unsupported.SetAllowCursorHide(enable);
 }
示例#5
0
 private void AllowCursorLockAndHide(bool enable)
 {
     Unsupported.SetAllowCursorLock(enable);
     Unsupported.SetAllowCursorHide(enable);
 }
        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;
            Rect renderRect         = EditorGUIUtility.PointsToPixels(gameViewRenderRect);
            bool fitsInsideRect;
            Rect constrainedGameViewRenderRect = GameView.GetConstrainedGameViewRenderRect(renderRect, this.selectedSizeIndex, out fitsInsideRect);
            Rect rect       = EditorGUIUtility.PixelsToPoints(constrainedGameViewRenderRect);
            Rect rect2      = GUIClip.Unclip(rect);
            Rect cameraRect = EditorGUIUtility.PointsToPixels(rect2);

            base.SetInternalGameViewRect(rect2);
            EditorGUIUtility.AddCursorRect(rect, 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);
            }
            if (type == EventType.Repaint)
            {
                bool flag = EditorGUIUtility.IsDisplayReferencedByCameras(this.m_TargetDisplay);
                if (!this.currentGameViewSize.isFreeAspectRatio || !InternalEditorUtility.HasFullscreenCamera() || !flag)
                {
                    GUI.Box(gameViewRenderRect, GUIContent.none, "GameViewBackground");
                    if (!InternalEditorUtility.HasFullscreenCamera())
                    {
                        float[] array = new float[]
                        {
                            30f,
                            gameViewRenderRect.height / 2f - 10f,
                            gameViewRenderRect.height - 10f
                        };
                        for (int i = 0; i < array.Length; i++)
                        {
                            int num = (int)array[i];
                            GUI.Label(new Rect(gameViewRenderRect.width / 2f - 100f, (float)num, 300f, 20f), "Scene is missing a fullscreen camera", "WhiteLargeLabel");
                        }
                    }
                }
                Vector2 s_EditorScreenPointOffset = GUIUtility.s_EditorScreenPointOffset;
                GUIUtility.s_EditorScreenPointOffset = Vector2.zero;
                SavedGUIState savedGUIState = SavedGUIState.Create();
                if (this.ShouldShowMultiDisplayOption())
                {
                    EditorGUIUtility.RenderGameViewCamerasInternal(cameraRect, this.m_TargetDisplay, this.m_Gizmos, true);
                }
                else
                {
                    EditorGUIUtility.RenderGameViewCamerasInternal(cameraRect, 0, this.m_Gizmos, true);
                }
                GL.sRGBWrite = false;
                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 flag2 = rect.Contains(Event.current.mousePosition);
                if (Event.current.rawType == EventType.MouseDown && !flag2)
                {
                    return;
                }
                Vector2 mousePosition = Event.current.mousePosition;
                Vector2 vector        = mousePosition - rect.position;
                vector = EditorGUIUtility.PointsToPixels(vector);
                Event.current.mousePosition = vector;
                Event.current.displayIndex  = this.m_TargetDisplay;
                EditorGUIUtility.QueueGameViewInputEvent(Event.current);
                bool flag3 = true;
                if (Event.current.rawType == EventType.MouseUp && !flag2)
                {
                    flag3 = false;
                }
                if (type == EventType.ExecuteCommand || type == EventType.ValidateCommand)
                {
                    flag3 = false;
                }
                if (flag3)
                {
                    Event.current.Use();
                }
                else
                {
                    Event.current.mousePosition = mousePosition;
                }
            }
            this.ShowResolutionWarning(new Rect(gameViewRenderRect.x, gameViewRenderRect.y, 200f, 20f), fitsInsideRect, constrainedGameViewRenderRect.size);
            if (this.m_Stats)
            {
                GameViewGUI.GameViewStatsGUI();
            }
        }
示例#7
0
        private void OnGUI()
        {
            if ((base.position.size * EditorGUIUtility.pixelsPerPoint) != this.m_LastWindowPixelSize)
            {
                this.UpdateZoomAreaAndParent();
            }
            this.DoToolbarGUI();
            this.CopyDimensionsToParentView();
            EditorGUIUtility.AddCursorRect(this.viewInWindow, MouseCursor.CustomCursor);
            EventType type = Event.current.type;

            if ((type == EventType.MouseDown) && this.viewInWindow.Contains(Event.current.mousePosition))
            {
                this.AllowCursorLockAndHide(true);
            }
            else if ((type == EventType.KeyDown) && (Event.current.keyCode == KeyCode.Escape))
            {
                Unsupported.SetAllowCursorLock(false);
            }
            bool flag = EditorApplication.isPlaying && !EditorApplication.isPaused;

            this.m_ZoomArea.hSlider          = !flag && (this.m_ZoomArea.shownArea.width < this.targetInContent.width);
            this.m_ZoomArea.vSlider          = !flag && (this.m_ZoomArea.shownArea.height < this.targetInContent.height);
            this.m_ZoomArea.enableMouseInput = !flag;
            this.ConfigureZoomArea();
            if (flag)
            {
                GUIUtility.keyboardControl = 0;
            }
            Vector2 mousePosition = Event.current.mousePosition;
            Vector2 vector2       = this.WindowToGameMousePosition(mousePosition);

            GUI.color = Color.white;
            EventType type2 = Event.current.type;

            this.m_ZoomArea.BeginViewGUI();
            switch (type)
            {
            case EventType.Layout:
            case EventType.Used:
                break;

            case EventType.Repaint:
            {
                GUI.Box(this.m_ZoomArea.drawRect, GUIContent.none, Styles.gameViewBackgroundStyle);
                Vector2 vector3 = GUIUtility.s_EditorScreenPointOffset;
                GUIUtility.s_EditorScreenPointOffset = Vector2.zero;
                SavedGUIState state = SavedGUIState.Create();
                this.ConfigureTargetTexture((int)this.targetSize.x, (int)this.targetSize.y);
                if (this.m_ClearInEditMode && !EditorApplication.isPlaying)
                {
                    this.ClearTargetTexture();
                }
                int targetDisplay = 0;
                if (this.ShouldShowMultiDisplayOption())
                {
                    targetDisplay = this.m_TargetDisplay;
                }
                if (this.m_TargetTexture.IsCreated())
                {
                    EditorGUIUtility.RenderGameViewCamerasInternal(this.m_TargetTexture, targetDisplay, GUIClip.Unclip(this.viewInWindow), vector2, this.m_Gizmos);
                    state.ApplyAndForget();
                    GUIUtility.s_EditorScreenPointOffset = vector3;
                    GUI.BeginGroup(this.m_ZoomArea.drawRect);
                    GL.sRGBWrite = this.m_CurrentColorSpace == ColorSpace.Linear;
                    GUI.DrawTexture(this.deviceFlippedTargetInView, this.m_TargetTexture, ScaleMode.StretchToFill, false);
                    GL.sRGBWrite = false;
                    GUI.EndGroup();
                }
                break;
            }

            default:
            {
                if (WindowLayout.s_MaximizeKey.activated && (!EditorApplication.isPlaying || EditorApplication.isPaused))
                {
                    return;
                }
                bool flag2 = this.viewInWindow.Contains(Event.current.mousePosition);
                if ((Event.current.rawType == EventType.MouseDown) && !flag2)
                {
                    return;
                }
                Event.current.mousePosition = vector2;
                Event.current.displayIndex  = this.m_TargetDisplay;
                EditorGUIUtility.QueueGameViewInputEvent(Event.current);
                bool flag3 = true;
                if ((Event.current.rawType == EventType.MouseUp) && !flag2)
                {
                    flag3 = false;
                }
                switch (type)
                {
                case EventType.ExecuteCommand:
                case EventType.ValidateCommand:
                    flag3 = false;
                    break;
                }
                if (flag3)
                {
                    Event.current.Use();
                }
                else
                {
                    Event.current.mousePosition = mousePosition;
                }
                break;
            }
            }
            this.m_ZoomArea.EndViewGUI();
            if ((type2 == EventType.ScrollWheel) && (Event.current.type == EventType.Used))
            {
                EditorApplication.update = (EditorApplication.CallbackFunction)Delegate.Remove(EditorApplication.update, new EditorApplication.CallbackFunction(this.SnapZoomDelayed));
                EditorApplication.update = (EditorApplication.CallbackFunction)Delegate.Combine(EditorApplication.update, new EditorApplication.CallbackFunction(this.SnapZoomDelayed));
                s_LastScrollTime         = EditorApplication.timeSinceStartup;
            }
            this.EnforceZoomAreaConstraints();
            if (this.m_TargetTexture != null)
            {
                if (this.m_ZoomArea.scale.y < 1f)
                {
                    this.m_TargetTexture.filterMode = UnityEngine.FilterMode.Bilinear;
                }
                else
                {
                    this.m_TargetTexture.filterMode = UnityEngine.FilterMode.Point;
                }
            }
            if (this.m_NoCameraWarning && !EditorGUIUtility.IsDisplayReferencedByCameras(this.m_TargetDisplay))
            {
                GUI.Label(this.warningPosition, GUIContent.none, EditorStyles.notificationBackground);
                string str = !this.ShouldShowMultiDisplayOption() ? string.Empty : DisplayUtility.GetDisplayNames()[this.m_TargetDisplay].text;
                string t   = $"{str}
No cameras rendering";
                EditorGUI.DoDropShadowLabel(this.warningPosition, EditorGUIUtility.TempContent(t), EditorStyles.notificationText, 0.3f);
            }
            if (this.m_Stats)
            {
                GameViewGUI.GameViewStatsGUI();
            }
        }
示例#8
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();
            }
        }
示例#9
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();
            }
        }