public void Close() { if (m_Window) { m_Window.Close(); } DestroyImmediate(this, true); s_Get = null; }
public static void CloseWindows() { try { TooltipView.Close(); } catch (Exception) { } UnityEngine.Object[] array = Resources.FindObjectsOfTypeAll(typeof(ContainerWindow)); UnityEngine.Object[] array2 = array; for (int i = 0; i < array2.Length; i++) { ContainerWindow containerWindow = (ContainerWindow)array2[i]; try { containerWindow.Close(); } catch (Exception) { } } UnityEngine.Object[] array3 = Resources.FindObjectsOfTypeAll(typeof(EditorWindow)); if (array3.Length != 0) { string text = ""; UnityEngine.Object[] array4 = array3; for (int j = 0; j < array4.Length; j++) { EditorWindow editorWindow = (EditorWindow)array4[j]; text = text + "\n" + editorWindow.GetType().Name; UnityEngine.Object.DestroyImmediate(editorWindow, true); } UnityEngine.Debug.LogError("Failed to destroy editor windows: #" + array3.Length + text); } UnityEngine.Object[] array5 = Resources.FindObjectsOfTypeAll(typeof(View)); if (array5.Length != 0) { string text2 = ""; UnityEngine.Object[] array6 = array5; for (int k = 0; k < array6.Length; k++) { View view = (View)array6[k]; text2 = text2 + "\n" + view.GetType().Name; UnityEngine.Object.DestroyImmediate(view, true); } UnityEngine.Debug.LogError("Failed to destroy views: #" + array5.Length + text2); } }
void MakeSureConsoleAlwaysOnlyOne() { // make sure that console window is always open as only one. if (ms_ConsoleWindow != null) { // get the container window of this console window. ContainerWindow cw = ms_ConsoleWindow.m_Parent.window; // the container window must not be main view(prevent from quitting editor). if (cw.rootView.GetType() != typeof(MainView)) { cw.Close(); } } }
public static bool LoadWindowLayout(string path, bool newProjectLayoutWasCreated, bool setLastLoadedLayoutName, bool keepMainWindow) { Rect mainWindowPosition = new Rect(); UnityObject[] containers = Resources.FindObjectsOfTypeAll(typeof(ContainerWindow)); foreach (ContainerWindow window in containers) { if (window.showMode == ShowMode.MainWindow) { mainWindowPosition = window.position; } } bool layoutLoadingIssue = false; // Load new windows and show them try { ContainerWindow.SetFreezeDisplay(true); CloseWindows(keepMainWindow); ContainerWindow mainWindowToSetSize = null; ContainerWindow mainWindow = null; UnityObject[] remainingContainers = Resources.FindObjectsOfTypeAll(typeof(ContainerWindow)); foreach (ContainerWindow window in remainingContainers) { if (mainWindow == null && window.showMode == ShowMode.MainWindow) { mainWindow = window; } else { window.Close(); } } // Load data UnityObject[] loadedWindows = InternalEditorUtility.LoadSerializedFileAndForget(path); if (loadedWindows == null || loadedWindows.Length == 0) { throw new ArgumentException("Window layout at '" + path + "' could not be loaded."); } List <UnityObject> newWindows = new List <UnityObject>(); // At this point, unparented editor windows are neither desired nor desirable. // This can be caused by (legacy) serialization of FallbackEditorWindows or // other serialization hiccups (note that unparented editor windows should not exist in theory). // Same goes for empty DockAreas (no panes). Leave them behind. for (int i = 0; i < loadedWindows.Length; i++) { UnityObject o = loadedWindows[i]; EditorWindow editorWin = o as EditorWindow; if (editorWin != null) { if (editorWin.m_Parent == null) { UnityObject.DestroyImmediate(editorWin, true); Console.WriteLine("LoadWindowLayout: Removed unparented EditorWindow while reading window layout: window #" + i + ", type=" + o.GetType() + ", instanceID=" + o.GetInstanceID()); layoutLoadingIssue = true; continue; } } else { ContainerWindow cw = o as ContainerWindow; if (cw != null && cw.rootView == null) { cw.Close(); UnityObject.DestroyImmediate(cw, true); continue; } DockArea dockArea = o as DockArea; if (dockArea != null && dockArea.m_Panes.Count == 0) { dockArea.Close(null); UnityObject.DestroyImmediate(dockArea, true); continue; } // Host views that donot hold any containers are not desirable at this stage HostView hostview = o as HostView; if (hostview != null && hostview.actualView == null) { UnityObject.DestroyImmediate(hostview, true); continue; } } newWindows.Add(o); } for (int i = 0; i < newWindows.Count; i++) { ContainerWindow cur = newWindows[i] as ContainerWindow; if (cur != null && cur.showMode == ShowMode.MainWindow) { if (mainWindow == null) { mainWindow = cur; } else { mainWindow.rootView = cur.rootView; UnityObject.DestroyImmediate(cur, true); cur = mainWindow; newWindows[i] = null; } if (mainWindowPosition.width != 0.0) { mainWindowToSetSize = cur; mainWindowToSetSize.position = mainWindowPosition; } break; } } for (int i = 0; i < newWindows.Count; i++) { UnityObject o = newWindows[i]; if (o == null) { continue; } if (o.GetType() == null) { Console.WriteLine("LoadWindowLayout: Error while reading window layout: window #" + i + " type is null, instanceID=" + o.GetInstanceID()); layoutLoadingIssue = true; // Keep going } else { if (newProjectLayoutWasCreated) { MethodInfo method = o.GetType().GetMethod("OnNewProjectLayoutWasCreated", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (method != null) { method.Invoke(o, null); } } } } if (mainWindowToSetSize) { mainWindowToSetSize.position = mainWindowPosition; mainWindowToSetSize.OnResize(); } // Always show main window before other windows. So that other windows can // get their parent/owner. if (mainWindow == null) { Debug.LogError("Error while reading window layout: no main window found"); throw new Exception(); } mainWindow.Show(mainWindow.showMode, loadPosition: true, displayImmediately: true, setFocus: true); // Show other windows for (int i = 0; i < newWindows.Count; i++) { if (newWindows[i] == null) { continue; } EditorWindow win = newWindows[i] as EditorWindow; if (win) { win.minSize = win.minSize; // Causes minSize to be propagated upwards to parents! } ContainerWindow containerWindow = newWindows[i] as ContainerWindow; if (containerWindow && containerWindow != mainWindow) { containerWindow.Show(containerWindow.showMode, loadPosition: false, displayImmediately: true, setFocus: true); } } // Unmaximize maximized GameView if maximize on play is enabled GameView gameView = GetMaximizedWindow() as GameView; if (gameView != null && gameView.maximizeOnPlay) { Unmaximize(gameView); } } catch (Exception ex) { Debug.LogError("Failed to load window layout: " + ex); int option = 0; UnityObject[] containerWindows = Resources.FindObjectsOfTypeAll(typeof(ContainerWindow)); // Only show dialog if an actual window is present. If not, revert to default immediately if (!Application.isTestRun && containerWindows.Length > 0) { option = EditorUtility.DisplayDialogComplex("Failed to load window layout", "This can happen if layout contains custom windows and there are compile errors in the project.", "Load Default Layout", "Quit", "Revert Factory Settings"); } switch (option) { case 0: LoadDefaultLayout(); break; case 1: EditorApplication.Exit(0); break; case 2: RevertFactorySettings(); break; } return(false); } finally { ContainerWindow.SetFreezeDisplay(false); if (setLastLoadedLayoutName && Path.GetExtension(path) == ".wlt") { Toolbar.lastLoadedLayoutName = Path.GetFileNameWithoutExtension(path); } else { Toolbar.lastLoadedLayoutName = null; } } if (layoutLoadingIssue) { Debug.Log("The editor layout could not be fully loaded, this can happen when the layout contains EditorWindows not available in this project"); } return(true); }