/// <summary>
        /// Closes all fullscreen editor windows.
        /// </summary>
        /// <returns>True if at least one fullscreen window was closed.</returns>
        public static bool CloseAllEditorFullscreenWindows()
        {
            bool closedAtLeastOneFullscreen = false;

            try
            {
                var allWinStates = EditorFullscreenState.fullscreenState.window.ToArray();
                foreach (var win in allWinStates)
                {
                    if (win.EditorWin != null && win.WindowType != EditorFullscreenState.mainWindowType)
                    {
                        if (win.IsFullscreen)
                        {
                            closedAtLeastOneFullscreen = true;
                        }
                        win.EditorWin.SetFullscreen(false);
                    }
                }
            }
            catch { }

            if (EditorMainWindow.IsFullscreen())
            {
                closedAtLeastOneFullscreen = true;
            }
            EditorMainWindow.SetFullscreen(false);

            EditorFullscreenState.fullscreenState.CleanDeletedWindows();
            EditorFullscreenState.TriggerFullscreenEvent(null, null, Vector2.zero, closedAtLeastOneFullscreen);
            return(closedAtLeastOneFullscreen);
        }
Example #2
0
        /// <summary>
        /// Closes all fullscreen editor windows.
        /// </summary>
        /// <returns>True if at least one fullscreen window was closed.</returns>
        public static bool CloseAllEditorFullscreenWindows()
        {
            bool closedAtLeastOneFullscreen = false;
            int  numOfClosedFullscreens     = 0;

            EWFDebugging.LogLine("Closing all fullscreen windows.");
            try
            {
                var allWinStates = EditorFullscreenState.fullscreenState.window.ToArray();
                foreach (var win in allWinStates)
                {
                    if (win.EditorWin != null && win.WindowType != EditorFullscreenState.MainWindowType)
                    {
                        if (win.IsFullscreen)
                        {
                            closedAtLeastOneFullscreen = true;
                            if (EditorDisplay.ClosestToPoint(win.FullscreenAtPosition).Locked)
                            {
                                EditorFullscreenState.RunAfterDisplayNotLocked(win.FullscreenAtPosition, () => CloseAllEditorFullscreenWindows()); return(true);
                            }
                            if (settings.debugModeEnabled)
                            {
                                EWFDebugging.Log("Closing fullscreen for window, title: " + win.WindowTitle + " type: " + win.WindowType + " FullscreenAtPosition: " + win.FullscreenAtPosition + " Fullscreen in Bounds: " + win.ScreenBounds);
                            }
                            win.EditorWin.SetFullscreen(false);
                            win.containerWindow = null;
                            win.EditorWin       = null; //Causes the fullscreen state to be removed in CleanDeletedWindows();
                            numOfClosedFullscreens++;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                EWFDebugging.LogError("Error when closing all fullscreen windows: " + e.Message);
            }

            if (EditorMainWindow.IsFullscreen())
            {
                closedAtLeastOneFullscreen = true;
                numOfClosedFullscreens++;
                EWFDebugging.Log("Closing main window fullscreen.");
            }
            EditorMainWindow.SetFullscreen(false);

            EditorFullscreenState.fullscreenState.CleanDeletedWindows();
            EditorFullscreenState.TriggerFullscreenEvent(null, null, Vector2.zero, closedAtLeastOneFullscreen);
            EWFDebugging.LogLine("numOfClosedFullscreens: " + numOfClosedFullscreens);
            return(closedAtLeastOneFullscreen);
        }
Example #3
0
 /// <summary> Toggle the toolbar for the specified window state, if it is fullscreen </summary>
 public static bool ToggleToolbarInFullscreen(WindowFullscreenState fullscreenWinState, bool showTopToolbar)
 {
     if (fullscreenWinState != null && fullscreenWinState.IsFullscreen)
     {
         if (fullscreenWinState.WindowType == mainWindowType)
         {
             EditorMainWindow.SetFullscreen(true, showTopToolbar);
         }
         else if (fullscreenWinState.EditorWin != null)
         {
             fullscreenWinState.EditorWin.SetFullscreen(true, showTopToolbar);
         }
     }
     return(showTopToolbar);
 }
Example #4
0
        internal static void LoadFullscreenState()
        {
            try
            {
                string fullscreenStateData = File.ReadAllText(Path.Combine(projectLibraryPath, FullscreenStateFilename));
                fullscreenState = SerializerUtility.Deserialize <FullscreenState>(fullscreenStateData);
            }
            catch (FileNotFoundException)
            {
            }
            catch (System.Exception e)
            {
                Debug.LogException(e);
            }

            if (fullscreenState.window == null)
            {
                fullscreenState.window = new List <WindowFullscreenState>();
            }

            var allFullscreenStates = fullscreenState.window.ToArray();
            WindowFullscreenState mainWindowFullscreenState = null;

            //Load types from assembly qualified names
            foreach (var state in allFullscreenStates)
            {
                try
                {
                    state.ActualType = Type.GetType(state.actualTypeAssemblyQualifiedName);
                    state.WindowType = Type.GetType(state.windowTypeAssemblyQualifiedName);
                }
                catch (System.Exception e)
                {
                    if (LogNonFatalErrors)
                    {
                        Debug.LogException(e);
                    }
                }
            }

            //Re-assign recreated window instances to their fullscreen states
            var allWins = Resources.FindObjectsOfTypeAll <EditorWindow>();
            var unassignedFullscreenWins = new List <EditorWindow>();

            foreach (var win in allWins)
            {
                if (win.GetShowMode() == EditorWindowExtensions.ShowMode.PopupMenu)
                {
                    unassignedFullscreenWins.Add(win);
                }
            }
            foreach (var state in allFullscreenStates)
            {
                if (state.EditorWin != null)
                {
                    unassignedFullscreenWins.Remove(state.EditorWin);
                }
                else if (state.WindowType == mainWindowType)
                {
                    mainWindowFullscreenState = state;
                }
                else if (state.IsFullscreen)
                {
                    foreach (var win in unassignedFullscreenWins)
                    {
                        var containerPosition = win.GetContainerPosition();
                        if (win.GetType() == state.ActualType && containerPosition.x == state.ContainerPosition.x && containerPosition.y == state.ContainerPosition.y)
                        {
                            state.EditorWin = win;
                            unassignedFullscreenWins.Remove(win);
                            break;
                        }
                    }
                }
            }

            loadedInitialState = true;

            //Find the window which was focused
            var focusedWindow = fullscreenState.window.Find(state => state.HasFocus == true);

            //Remake fullscreen windows
            foreach (var state in allFullscreenStates)
            {
                if (state.IsFullscreen)
                {
                    if (state.EditorWin != null)
                    {
                        state.EditorWin.SetFullscreen(true, state.FullscreenAtPosition);
                    }
                    else if (state.WindowType != mainWindowType)
                    {
                        ToggleFullscreen(state.ActualType, true, state.FullscreenAtPosition, state.ShowTopToolbar, state.CreatedAtGameStart);
                    }
                }
            }

            //Recreate the main window fullscreen state
            if (mainWindowFullscreenState != null && mainWindowFullscreenState.IsFullscreen)
            {
                var atPosition     = mainWindowFullscreenState.FullscreenAtPosition;
                var showTopToolbar = mainWindowFullscreenState.ShowTopToolbar;
                if (mainWindowFullscreenState.containerWindow == null || mainWindowFullscreenState.originalContainerWindow == null)
                {
                    fullscreenState.window.Remove(mainWindowFullscreenState); //Remove the old fullscreen state because the originalContainer needs to be reset
                }
                EditorMainWindow.SetFullscreen(true, showTopToolbar, atPosition);
            }

            //Remove fullscreen popup windows which don't have a fullscreen state
            foreach (var win in unassignedFullscreenWins)
            {
                if (win != null)
                {
                    if (win.GetContainerWindow() != null)
                    {
                        win.Close();
                    }
                    else
                    {
                        UnityEngine.Object.DestroyImmediate(win, true);
                    }
                }
            }
            fullscreenState.CleanDeletedWindows();

            //Bring any fullscreen window which is on top of the main window to the front.
            try
            {
                var windowOverMain = fullscreenState.window.Find(state => state.IsFullscreen && state.EditorWin != null && EditorDisplay.ClosestToPoint(state.FullscreenAtPosition).Bounds == EditorDisplay.ClosestToPoint(EditorMainWindow.position.center).Bounds);
                if (windowOverMain != null)
                {
                    GiveFocusAndBringToFront(windowOverMain.EditorWin);
                }
            }
            catch { }

            //Refocus the window which was previously focused
            if (focusedWindow != null && focusedWindow.EditorWin != null)
            {
                GiveFocusAndBringToFront(focusedWindow.EditorWin);
            }

            //Toggle fullscreen for states which were queued up before load was complete
            foreach (var state in queuedStatesToToggleOnLoad)
            {
                ToggleFullscreen(state.ActualType, state.CloseOnExitFullscreen, state.FullscreenAtPosition, state.ShowTopToolbar, state.CreatedAtGameStart);
            }
            queuedStatesToToggleOnLoad.Clear();
            if (RunOnNextLoadMethods != null)
            {
                RunOnNextLoadMethods.Invoke();
                RunOnNextLoadMethods = null;
            }
        }