Пример #1
0
        /// <summary> Get the EditorDisplay which currently contains the fullscreen editorWindow </summary>
        internal static EditorDisplay GetFullscreenDisplay(this EditorWindow editorWindow)
        {
            var           fullscreenState = EditorFullscreenState.FindWindowState(editorWindow);
            EditorDisplay display         = null;

            if (fullscreenState != null)
            {
                display = EditorDisplay.ClosestToPoint(fullscreenState.FullscreenAtPosition);
            }
            return(display);
        }
Пример #2
0
        /// <summary> Toggle fullscreen for a window type </summary>
        public static bool ToggleFullscreen(Type windowType, bool createNewWindow, Vector2 atPosition, bool showTopToolbar, bool triggeredOnPlayStateChange)
        {
            var windowState = EditorFullscreenState.FindWindowState(null, windowType, EditorDisplay.ClosestToPoint(atPosition));

            if (showTopToolbar)
            {
                windowState.ShowTopToolbar = true;
            }
            if (triggeredOnPlayStateChange && !windowState.IsFullscreen)
            {
                windowState.CreatedAtGameStart = true;
            }
            return(ToggleFullscreen(windowState, createNewWindow, atPosition));
        }
Пример #3
0
        /// <summary> Set fullscreen with the option to show or hide the top tabs </summary>
        public static void SetFullscreen(this EditorWindow editorWindow, bool setFullscreen, Vector2 atPosition, bool showTopToolbar)
        {
            var fullscreenState = EditorFullscreenState.FindWindowState(editorWindow);

            if (editorWindow.GetWindowType() == FS.gameViewType)
            {
                if (showTopToolbar && !fullscreenState.ShowTopToolbar)
                {
                    fullscreenState.CursorLockModePreShowTopToolbar = Cursor.lockState;
                    Cursor.lockState = CursorLockMode.None; //Enable cursor when top tab is enabled
                }
                else if (!showTopToolbar && fullscreenState.ShowTopToolbar)
                {
                    Cursor.lockState = fullscreenState.CursorLockModePreShowTopToolbar; //Reset cursor lock mode when top tab is disabled
                }
            }

            fullscreenState.ShowTopToolbar = showTopToolbar;
            SetFullscreen(fullscreenState.EditorWin, setFullscreen, atPosition);
        }
Пример #4
0
        /// <summary>
        /// Exit all game views except for a single one (Multiple game views showing at the same time can cause FPS drops in-game)
        /// </summary>
        /// <param name="exceptForThisWindow">This is the only exception. Will not be closed.</param>
        public static void ExitAllGameViews(EditorWindow exceptForThisWindow)
        {
            var gameViews   = (EditorWindow[])Resources.FindObjectsOfTypeAll(EditorFullscreenState.GameViewType);
            var exceptState = EditorFullscreenState.FindWindowState(exceptForThisWindow);

            foreach (var win in gameViews)
            {
                var state = EditorFullscreenState.FindWindowState(win);
                if (exceptState != null && exceptState.CreatedAtGameStart && state != null && state.CreatedAtGameStart)
                {
                    //These game windows were created together at game start, so don't close them.
                    continue;
                }
                else
                {
                    if (win != exceptForThisWindow)
                    {
                        state.CloseOnExitFullscreen = true;
                        win.SetFullscreen(false);
                    }
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Toggle fullscreen for a window type (Creates a new fullscreen window if none already exists).
        /// </summary>
        /// <param name="windowType">The type of the window to create a fullscreen for.</param>
        /// <returns>True if the window type became fullscreen. False if fullscreen was exited.</returns>
        public static bool ToggleFullscreen(Type windowType)
        {
            var fullscreenState = EditorFullscreenState.FindWindowState(windowType);

            return(ToggleFullscreen(fullscreenState, true));
        }
Пример #6
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);
        }
Пример #7
0
        /// <summary> Returns true if the EditorWindow is currently fullscreen on the screen at a position </summary>
        public static bool IsFullscreen(this EditorWindow editorWindow, Vector2 atPosition)
        {
            var fullscreenState = EditorFullscreenState.FindWindowState(editorWindow);

            return(fullscreenState.IsFullscreen && editorWindow.IsFullscreenOnDisplay(EditorDisplay.ClosestToPoint(atPosition)));
        }