Пример #1
0
        /// <summary> Make the EditorWindow fullscreen, or return to how it was. Opens the fullscreen window on the screen at a specified position. </summary>
        public static void SetFullscreen(this EditorWindow editorWindow, bool setFullscreen, Vector2 atPosition)
        {
            Type windowType      = editorWindow.GetWindowType();
            var  fullscreenState = EditorFullscreenState.FindWindowState(editorWindow);

            CursorLockMode currentCursorLockMode = Cursor.lockState;

            if (setFullscreen == false)
            {
                if (fullscreenState.EditorWin != null)
                {
                    if (fullscreenState.CloseOnExitFullscreen)
                    {
                        //Close the window
                        editorWindow.Close();
                    }
                    else
                    {
                        //Restore the window
                        editorWindow.SetBorderlessPosition(fullscreenState.PreFullscreenPosition);
                        fullscreenState.EditorWin.minSize  = fullscreenState.PreFullscreenMinSize;
                        fullscreenState.EditorWin.maxSize  = fullscreenState.PreFullscreenMaxSize;
                        fullscreenState.EditorWin.position = fullscreenState.PreFullscreenPosition;

                        if (editorWindow.maximized != fullscreenState.PreFullscreenMaximized)
                        {
                            editorWindow.maximized = fullscreenState.PreFullscreenMaximized;
                        }
                    }
                }

                if (editorWindow.GetWindowType() == FS.gameViewType)
                {
                    Unsupported.SetAllowCursorLock(false); //Unlock the cursor when exiting game fullscreen
                }
                if (fullscreenState.UnfocusedGameViewOnEnteringFullscreen == true)
                {
                    //Refocus the first docked game view
                    var gameView = GetDockedGameView(editorWindow, false);
                    if (gameView != null)
                    {
                        gameView.Focus();
                    }
                }
            }
            else
            {
                if (!fullscreenState.IsFullscreen)
                {
                    fullscreenState.PreFullscreenPosition    = editorWindow.position;
                    fullscreenState.PreFullscreenPosition.y -= FS.windowTopPadding;
                    fullscreenState.PreFullscreenMinSize     = editorWindow.minSize;
                    fullscreenState.PreFullscreenMaxSize     = editorWindow.maxSize;
                    fullscreenState.PreFullscreenMaximized   = editorWindow.maximized;
                }

                editorWindow.SetWindowTitle("FULLSCREEN_WINDOW_" + editorWindow.GetInstanceID(), true);

                if (!editorWindow.IsFullscreen())
                {
                    editorWindow.maximized = false;

                    if (fullscreenState.ShowTopTabs)
                    {
                        editorWindow.Show();
                    }
                    else
                    {
                        editorWindow.ShowWithMode(ShowMode.PopupMenu);
                        editorWindow.SetSaveToLayout(true);
                    }

                    fullscreenState.FullscreenAtPosition = atPosition;
                    editorWindow.SetBorderlessPosition(new Rect(atPosition.x, atPosition.y, 100, 100));
                }
                else if (fullscreenState.IsFullscreen)
                {
                    //If already fullscreen, resize slightly to make sure the taskbar gets covered (E.g. when loading fullscreen state on startup)
                    var tempBounds = editorWindow.position;
                    tempBounds.yMax -= 1;
                    editorWindow.SetBorderlessPosition(tempBounds);
                }

                fullscreenState.ScreenBounds = editorWindow.MakeFullscreenWindow(!fullscreenState.ShowTopToolbar, atPosition);
                editorWindow.ExitFullscreenForOtherWindowsOnScreen(atPosition);

                fullscreenState.WindowName   = editorWindow.name;
                fullscreenState.EditorWin    = editorWindow;
                fullscreenState.IsFullscreen = true;

                //Usability improvement for Unity bug where only one visible game window accepts input. (Unfocus docked game views if opening fullscreen view on the same screen.)
                try
                {
                    var gameView = GetDockedGameView(editorWindow, true);
                    if (gameView != null)
                    {
                        bool onSameDisplay = EditorDisplay.ClosestToPoint(gameView.position.center).Bounds.Contains(atPosition);
                        var  hostView      = gameView.GetHostView();
                        if (onSameDisplay && hostView != null && FS.dockAreaType != null)
                        {
                            FieldInfo m_Panes       = FS.dockAreaType.GetField("m_Panes", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                            var       dockAreaPanes = (List <EditorWindow>)m_Panes.GetValue(hostView);
                            foreach (var sibling in dockAreaPanes)
                            {
                                if (sibling.GetType() != FS.gameViewType)
                                {
                                    sibling.Focus(); //Focus the first non-game sibling of the docked game view
                                    fullscreenState.UnfocusedGameViewOnEnteringFullscreen = true;
                                    break;
                                }
                            }
                        }
                    }
                }
                catch (System.Exception e)
                {
                    if (FS.LogNonFatalErrors)
                    {
                        Debug.LogException(e);
                    }
                }

                editorWindow.Focus();

                Cursor.lockState = currentCursorLockMode; //Ensure that the cursor lock mode remains the same when entering fullscreen
            }

            FS.SaveFullscreenState();
            FS.TriggerFullscreenEvent(editorWindow, windowType, atPosition, setFullscreen);
        }