Exemple #1
0
        /// <summary> Toggle the toolbar in the active window if it is fullscreen </summary>
        public static bool ToggleToolbarInFullscreen()
        {
            bool setShowTopToolbar  = false;
            var  fullscreenWinState = FocusedWindowState;

            if (fullscreenWinState == null || !fullscreenWinState.IsFullscreen)
            {
                //If the current EditorWindow state isn't fullscreen, toggle the toolbar of the main window if that is fullscreen.
                fullscreenWinState = EditorMainWindow.GetWindowFullscreenState();
            }

            //If no fullscreen window is focused, toggle the top tab for the last top-tab-toggled fullscreen window.
            if ((fullscreenWinState == null || !fullscreenWinState.IsFullscreen) && lastWinStateToToggleTopTabs != null)
            {
                fullscreenWinState = lastWinStateToToggleTopTabs;
            }

            if (fullscreenWinState != null)
            {
                lastWinStateToToggleTopTabs = fullscreenWinState;
                setShowTopToolbar           = !fullscreenWinState.ShowTopToolbar;
                return(ToggleToolbarInFullscreen(fullscreenWinState, setShowTopToolbar));
            }
            else
            {
                lastWinStateToToggleTopTabs = null;
                return(false);
            }
        }
        /// <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);
        }
Exemple #3
0
        /// <summary>
        /// Returns true if a window type is fullscreen on the screen at the specified position.
        /// </summary>
        public static bool WindowTypeIsFullscreenOnScreenAtPosition(Type windowType, Vector2 atPosition)
        {
            bool isFullscreen = false;

            //Main Window
            if (windowType == mainWindowType)
            {
                return(EditorMainWindow.IsFullscreenAtPosition(atPosition));
            }

            var wins = Resources.FindObjectsOfTypeAll <EditorWindow>();

            foreach (var editorWin in wins)
            {
                if (editorWin.GetType() == windowType || editorWin.GetWindowType() == windowType)
                {
                    var winState = FindWindowState(editorWin);
                    if (winState.IsFullscreen)
                    {
                        if (editorWin.GetContainerPosition().Contains(atPosition) && editorWin.IsFullscreen())
                        {
                            isFullscreen = true;
                            break;
                        }
                    }
                }
            }
            return(isFullscreen);
        }
Exemple #4
0
        private static WindowFullscreenState AddWindowState(EditorWindow editorWin, Type windowType, Type actualType)
        {
            var winState = new WindowFullscreenState();

            winState.WindowType = windowType;
            winState.ActualType = actualType;

            if (editorWin != null)
            {
                winState.SetEditorWin(editorWin);
            }
            else if (windowType == mainWindowType)
            {
                winState.WindowName              = mainWindowType.Name;
                winState.WindowTitle             = "Unity Editor";
                winState.containerWindow         = (ScriptableObject)EditorMainWindow.FindContainerWindow();
                winState.originalContainerWindow = winState.containerWindow;
            }

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

            fullscreenState.window.Add(winState);
            return(winState);
        }
        private static bool ToggleGameViewFullscreen(bool triggeredOnPlayStateChange)
        {
            EditorFullscreenSettings.FullscreenOption fullscreenOps;
            if (triggeredOnPlayStateChange)
            {
                fullscreenOps = EditorFullscreenSettings.settings.openFullscreenOnGameStart;
            }
            else
            {
                fullscreenOps = EditorFullscreenSettings.GetFullscreenOptionsForWindowType(EditorFullscreenState.gameViewType);
            }
            bool setFullscreen = !EditorFullscreenState.WindowTypeIsFullscreenAtOptionsSpecifiedPosition(EditorFullscreenState.gameViewType, fullscreenOps);

            EditorFullscreenState.RunOnLoad methodToRun;
            if (!triggeredOnPlayStateChange)
            {
                methodToRun = ToggleGameViewFullscreen;
            }
            else
            {
                methodToRun = ToggleGameViewFullscreenPlayStateWasChanged;
            }
            if (EditorFullscreenState.RunAfterInitialStateLoaded(methodToRun))
            {
                return(setFullscreen);
            }

            setFullscreen = EditorFullscreenState.ToggleFullscreenAtOptionsSpecifiedPosition(null, EditorFullscreenState.gameViewType, fullscreenOps, triggeredOnPlayStateChange);
            var focusedWindow = EditorWindow.focusedWindow;

            EditorMainWindow.Focus();
            if (focusedWindow != null)
            {
                focusedWindow.Focus();
            }

            if (!triggeredOnPlayStateChange)
            {
                bool isPlaying = EditorApplication.isPlaying || EditorApplication.isPlayingOrWillChangePlaymode;
                if (settings.startGameWhenEnteringFullscreen && !isPlaying && setFullscreen)
                {
                    //Enter play mode
                    EditorApplication.ExecuteMenuItem("Edit/Play");
                }
                else if (settings.stopGameWhenExitingFullscreen != EditorFullscreenSettings.StopGameWhenExitingFullscreen.Never && isPlaying && !setFullscreen)
                {
                    if (settings.stopGameWhenExitingFullscreen == EditorFullscreenSettings.StopGameWhenExitingFullscreen.WhenAnyFullscreenGameViewIsExited || !WindowTypeIsFullscreen(EditorFullscreenState.gameViewType))
                    {
                        //Exit play mode
                        EditorApplication.ExecuteMenuItem("Edit/Play");
                    }
                }
            }
            return(setFullscreen);
        }
Exemple #6
0
        /// <summary>
        /// Returns true if a window type is fullscreen on the screen specified by the options for opening that window type.
        /// </summary>
        public static bool WindowTypeIsFullscreenAtOptionsSpecifiedPosition(Type windowType)
        {
            var fullscreenOptions = EditorFullscreenSettings.GetFullscreenOptionsForWindowType(windowType);

            //Main Window
            if (windowType == mainWindowType)
            {
                return(EditorMainWindow.IsFullscreenAtPosition(GetOptionsSpecifiedFullscreenOpenAtPosition(null, windowType, fullscreenOptions)));
            }

            //Any Other Editor Window
            return(WindowTypeIsFullscreenAtOptionsSpecifiedPosition(windowType, fullscreenOptions));
        }
Exemple #7
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);
        }
Exemple #8
0
        /// <summary> Toggle fullscreen for a window state, on the screen at position </summary>
        private static bool ToggleFullscreen(WindowFullscreenState windowState, bool createNewWindow, Vector2 atPosition)
        {
            if (windowState == null)
            {
                throw new NullReferenceException("windowState is null. Cannot continue.");
            }

            if (!loadedInitialState)
            {
                windowState.CloseOnExitFullscreen = createNewWindow;
                windowState.FullscreenAtPosition  = atPosition;
                queuedStatesToToggleOnLoad.Add(windowState);

                if (LogNonFatalErrors)
                {
                    throw new TypeLoadException("The fullscreen state hasn't been loaded yet. Fullscreen toggle has been queued.");
                }
                else
                {
                    return(false);
                }
            }
            if (windowState.WindowType == mainWindowType)
            {
                return(EditorMainWindow.ToggleFullscreen(windowState.ShowTopToolbar, atPosition));
            }

            if (windowState.EditorWin == null || (!windowState.IsFullscreen && createNewWindow))
            {
                if (windowState.ActualType == typeof(SceneView))
                {
                    windowState.ActualType = typeof(CustomSceneView);
                }                                                                                                      //Always create CustomSceneView for SceneView
                var win = EditorWindowExtensions.CreateWindow(windowState.ActualType);
                windowState.SetEditorWin(win);

                if (windowState.ActualType == typeof(CustomSceneView) || win.GetWindowType() == gameViewType)
                {
                    win.SetWindowTitle(windowState.WindowName, true); //Reset title content on custom Scene and Game views to prevent icon not found error.
                }
                windowState.CloseOnExitFullscreen = true;             //Since we are creating a new window, this window should close when fullscreen is exited

                bool setFullscreen = win.ToggleFullscreen(atPosition);
                return(setFullscreen);
            }
            else
            {
                return(windowState.EditorWin.ToggleFullscreen(atPosition));
            }
        }
Exemple #9
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);
 }
Exemple #10
0
        private static void InitializeInputWin()
        {
            //Close existing input wins except for one
            var allInputWins = (EditorInput[])Resources.FindObjectsOfTypeAll(typeof(EditorInput));

            for (int i = 0; i < allInputWins.Length; i++)
            {
                if (i == allInputWins.Length - 1)
                {
                    //Keep the last one
                    inputWin = allInputWins[i];
                }
                else
                {
                    allInputWins[i].Close();
                }
            }

            if (inputWin == null)
            {
                //If couldn't find an existing one, create a hidden EditorWindow to receive an editor event
                Rect winPos = new Rect(-5000, -5000, 1, 1);
                inputWin = CreateInstance <EditorInput>();
                inputWin.SetWindowTitle("EditorInputWin", true);

                inputWin.minSize  = winPos.size;
                inputWin.maxSize  = winPos.size;
                inputWin.position = winPos;

                inputWin.ShowWithMode(EditorWindowExtensions.ShowMode.NoShadow);
                inputWin.SetSaveToLayout(false);
                EditorMainWindow.Focus();
            }

#if UNITY_STANDALONE_WIN && (UNITY_5_0 || UNITY_5_1)
            inputWin.DisableKeyboardCapture();
            inputWin.InitKeyboardCapture();
#endif
        }
Exemple #11
0
        private static bool ToggleGameViewFullscreen(bool triggeredOnGameStart, int optionID)
        {
            EditorWindow            focusedWindow = null;
            List <FullscreenOption> allGameWins   = null;

            EditorFullscreenState.WindowFullscreenState state = null;
            bool setFullscreen;

            if (triggeredOnGameStart)
            {
                allGameWins   = settings.AllGameWindows;
                setFullscreen = true;
            }
            else
            {
                setFullscreen = !EditorFullscreenState.WindowTypeIsFullscreenAtOptionsSpecifiedPosition(EditorFullscreenState.GameViewType, settings.GetFullscreenOption(optionID));
            }

            EditorFullscreenState.RunOnLoad methodToRun;
            if (!triggeredOnGameStart)
            {
                methodToRun = () => ToggleGameViewFullscreen(false, optionID);
            }
            else
            {
                methodToRun = () => ToggleGameViewFullscreen(true, optionID);
            }
            if (EditorFullscreenState.RunAfterInitialStateLoaded(methodToRun))
            {
                return(setFullscreen);
            }

            if (triggeredOnGameStart)
            {
                for (int i = 0; i < allGameWins.Count; i++)
                {
                    if (allGameWins[i].openOnGameStart)
                    {
                        if (!EditorFullscreenState.WindowTypeIsFullscreenAtOptionsSpecifiedPosition(EditorFullscreenState.GameViewType, allGameWins[i]))
                        {
                            EditorFullscreenState.ToggleFullscreenUsingOptions(null, EditorFullscreenState.GameViewType, allGameWins[i], triggeredOnGameStart, false);
                        }
                    }
                }
            }
            else
            {
                state         = EditorFullscreenState.ToggleFullscreenUsingOptions(null, EditorFullscreenState.GameViewType, settings.GetFullscreenOption(optionID), triggeredOnGameStart, false, out setFullscreen);
                focusedWindow = EditorWindow.focusedWindow;
            }

            EditorMainWindow.Focus();
            if (focusedWindow != null)
            {
                focusedWindow.Focus();
            }

            if (!triggeredOnGameStart)
            {
                bool isPlaying = EditorApplication.isPlaying || EditorApplication.isPlayingOrWillChangePlaymode;
                if (settings.startGameWhenEnteringFullscreen && !isPlaying && setFullscreen)
                {
                    //Enter play mode
                    EditorApplication.ExecuteMenuItem("Edit/Play");
                }
                else if (settings.stopGameWhenExitingFullscreen != EditorFullscreenSettings.StopGameWhenExitingFullscreen.Never && isPlaying && !setFullscreen)
                {
                    if (settings.stopGameWhenExitingFullscreen == EditorFullscreenSettings.StopGameWhenExitingFullscreen.WhenAnyFullscreenGameViewIsExited || !WindowTypeIsFullscreen(EditorFullscreenState.GameViewType, state))
                    {
                        //Exit play mode
                        EditorApplication.ExecuteMenuItem("Edit/Play");
                    }
                }
            }
            return(setFullscreen);
        }
Exemple #12
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;
            }
        }