internal static void SaveFullscreenState() { try { fullscreenState.CleanDeletedWindows(); //Update state window container positions and focus before saving foreach (var state in fullscreenState.window) { if (state.EditorWin != null) { state.ContainerPosition = state.EditorWin.GetContainerPosition(); state.HasFocus = state.EditorWin == EditorWindow.focusedWindow; } } string fullscreenStateData = SerializerUtility.Serialize(fullscreenState); File.WriteAllText(Path.Combine(projectLibraryPath, FullscreenStateFilename), fullscreenStateData); } catch (IOException e) { Debug.LogException(e); } }
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; } }