public static void MaximizePresent(EditorWindow win) { ContainerWindow.SetFreezeDisplay(true); win.Focus(); CheckWindowConsistency(); ContainerWindow parentWindow = win.m_Parent.window; parentWindow.DisplayAllViews(); win.m_Parent.MakeVistaDWMHappyDance(); ContainerWindow.SetFreezeDisplay(false); }
public static bool LoadWindowLayout(string path, bool newProjectLayoutWasCreated) { Rect position = default(Rect); UnityEngine.Object[] array = Resources.FindObjectsOfTypeAll(typeof(ContainerWindow)); UnityEngine.Object[] array2 = array; for (int i = 0; i < array2.Length; i++) { ContainerWindow containerWindow = (ContainerWindow)array2[i]; if (containerWindow.showMode == ShowMode.MainWindow) { position = containerWindow.position; } } bool result; try { ContainerWindow.SetFreezeDisplay(true); WindowLayout.CloseWindows(); UnityEngine.Object[] array3 = InternalEditorUtility.LoadSerializedFileAndForget(path); List <UnityEngine.Object> list = new List <UnityEngine.Object>(); int j = 0; while (j < array3.Length) { UnityEngine.Object @object = array3[j]; EditorWindow editorWindow = @object as EditorWindow; if (editorWindow != null) { if (!(editorWindow.m_Parent == null)) { goto IL_17D; } UnityEngine.Object.DestroyImmediate(editorWindow, true); UnityEngine.Debug.LogError(string.Concat(new object[] { "Removed unparented EditorWindow while reading window layout: window #", j, ", type=", @object.GetType().ToString(), ", instanceID=", @object.GetInstanceID() })); } else { DockArea dockArea = @object as DockArea; if (!(dockArea != null) || dockArea.m_Panes.Count != 0) { goto IL_17D; } dockArea.Close(null); UnityEngine.Debug.LogError(string.Concat(new object[] { "Removed empty DockArea while reading window layout: window #", j, ", instanceID=", @object.GetInstanceID() })); } IL_187: j++; continue; IL_17D: list.Add(@object); goto IL_187; } ContainerWindow containerWindow2 = null; ContainerWindow containerWindow3 = null; for (int k = 0; k < list.Count; k++) { ContainerWindow containerWindow4 = list[k] as ContainerWindow; if (containerWindow4 != null && containerWindow4.showMode == ShowMode.MainWindow) { containerWindow3 = containerWindow4; if ((double)position.width != 0.0) { containerWindow2 = containerWindow4; containerWindow2.position = position; } } } for (int l = 0; l < list.Count; l++) { UnityEngine.Object object2 = list[l]; if (object2 == null) { UnityEngine.Debug.LogError("Error while reading window layout: window #" + l + " is null"); } else if (object2.GetType() == null) { UnityEngine.Debug.LogError(string.Concat(new object[] { "Error while reading window layout: window #", l, " type is null, instanceID=", object2.GetInstanceID() })); } else if (newProjectLayoutWasCreated) { MethodInfo method = object2.GetType().GetMethod("OnNewProjectLayoutWasCreated", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (method != null) { method.Invoke(object2, null); } } } if (containerWindow2) { containerWindow2.position = position; containerWindow2.OnResize(); } if (containerWindow3 == null) { UnityEngine.Debug.LogError("Error while reading window layout: no main window found"); throw new Exception(); } containerWindow3.Show(containerWindow3.showMode, true, true); for (int m = 0; m < list.Count; m++) { EditorWindow editorWindow2 = list[m] as EditorWindow; if (editorWindow2) { editorWindow2.minSize = editorWindow2.minSize; } ContainerWindow containerWindow5 = list[m] as ContainerWindow; if (containerWindow5 && containerWindow5 != containerWindow3) { containerWindow5.Show(containerWindow5.showMode, true, true); } } GameView gameView = WindowLayout.GetMaximizedWindow() as GameView; if (gameView != null && gameView.maximizeOnPlay) { WindowLayout.Unmaximize(gameView); } if (newProjectLayoutWasCreated) { if (UnityConnect.instance.online && UnityConnect.instance.loggedIn && UnityConnect.instance.shouldShowServicesWindow) { UnityConnectServiceCollection.instance.ShowService("Hub", true); } else { UnityConnectServiceCollection.instance.CloseServices(); } } } catch (Exception arg) { UnityEngine.Debug.LogError("Failed to load window layout: " + arg); int num = 0; if (!Application.isTestRun) { num = 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"); } if (num != 0) { if (num != 1) { if (num == 2) { WindowLayout.RevertFactorySettings(); } } else { EditorApplication.Exit(0); } } else { WindowLayout.LoadDefaultLayout(); } result = false; return(result); } finally { ContainerWindow.SetFreezeDisplay(false); if (Path.GetExtension(path) == ".wlt") { Toolbar.lastLoadedLayoutName = Path.GetFileNameWithoutExtension(path); } else { Toolbar.lastLoadedLayoutName = null; } } result = true; return(result); }
public static void Unmaximize(EditorWindow win) { HostView parent = win.m_Parent; if (parent == null) { UnityEngine.Debug.LogError("Host view was not found"); WindowLayout.RevertFactorySettings(); } else { UnityEngine.Object[] array = InternalEditorUtility.LoadSerializedFileAndForget(Path.Combine(WindowLayout.layoutsProjectPath, "CurrentMaximizeLayout.dwlt")); if (array.Length < 2) { UnityEngine.Debug.Log("Maximized serialized file backup not found"); WindowLayout.RevertFactorySettings(); } else { SplitView splitView = array[0] as SplitView; EditorWindow editorWindow = array[1] as EditorWindow; if (splitView == null) { UnityEngine.Debug.Log("Maximization failed because the root split view was not found"); WindowLayout.RevertFactorySettings(); } else { ContainerWindow window = win.m_Parent.window; if (window == null) { UnityEngine.Debug.Log("Maximization failed because the root split view has no container window"); WindowLayout.RevertFactorySettings(); } else { try { ContainerWindow.SetFreezeDisplay(true); if (!parent.parent) { throw new Exception(); } int idx = parent.parent.IndexOfChild(parent); Rect position = parent.position; View parent2 = parent.parent; parent2.RemoveChild(idx); parent2.AddChild(splitView, idx); splitView.position = position; DockArea dockArea = editorWindow.m_Parent as DockArea; int idx2 = dockArea.m_Panes.IndexOf(editorWindow); parent.actualView = null; win.m_Parent = null; dockArea.AddTab(idx2, win); dockArea.RemoveTab(editorWindow); UnityEngine.Object.DestroyImmediate(editorWindow); UnityEngine.Object[] array2 = array; for (int i = 0; i < array2.Length; i++) { UnityEngine.Object @object = array2[i]; EditorWindow editorWindow2 = @object as EditorWindow; if (editorWindow2 != null) { editorWindow2.MakeParentsSettingsMatchMe(); } } parent2.Initialize(parent2.window); parent2.position = parent2.position; splitView.Reflow(); UnityEngine.Object.DestroyImmediate(parent); win.Focus(); window.DisplayAllViews(); win.m_Parent.MakeVistaDWMHappyDance(); } catch (Exception arg) { UnityEngine.Debug.Log("Maximization failed: " + arg); WindowLayout.RevertFactorySettings(); } try { if (Application.platform == RuntimePlatform.OSXEditor && SystemInfo.operatingSystem.Contains("10.7") && SystemInfo.graphicsDeviceVendor.Contains("ATI")) { UnityEngine.Object[] array3 = Resources.FindObjectsOfTypeAll(typeof(GUIView)); for (int j = 0; j < array3.Length; j++) { GUIView gUIView = (GUIView)array3[j]; gUIView.Repaint(); } } } finally { ContainerWindow.SetFreezeDisplay(false); } } } } } }
public static bool LoadWindowLayout(string path, bool newProjectLayoutWasCreated) { 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(); // 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().ToString() + ", instanceID=" + o.GetInstanceID()); layoutLoadingIssue = true; continue; } } else { DockArea dockArea = o as DockArea; if (dockArea != null && dockArea.m_Panes.Count == 0) { dockArea.Close(null); Console.WriteLine("LoadWindowLayout: Removed empty DockArea while reading window layout: window #" + i + ", instanceID=" + o.GetInstanceID()); layoutLoadingIssue = true; continue; } } newWindows.Add(o); } ContainerWindow mainWindowToSetSize = null; ContainerWindow mainWindow = null; for (int i = 0; i < newWindows.Count; i++) { ContainerWindow cur = newWindows[i] as ContainerWindow; if (cur != null && cur.showMode == ShowMode.MainWindow) { mainWindow = cur; if (mainWindowPosition.width != 0.0) { mainWindowToSetSize = cur; mainWindowToSetSize.position = mainWindowPosition; } } } for (int i = 0; i < newWindows.Count; i++) { UnityObject o = newWindows[i]; if (o == null) { Console.WriteLine("LoadWindowLayout: Error while reading window layout: window #" + i + " is null"); layoutLoadingIssue = true; // Keep going } else 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 System.Exception(); } mainWindow.Show(mainWindow.showMode, true, true); // Show other windows for (int i = 0; i < newWindows.Count; i++) { 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, true, true); } } // Unmaximize maximized GameView if maximize on play is enabled GameView gameView = GetMaximizedWindow() as GameView; if (gameView != null && gameView.maximizeOnPlay) { Unmaximize(gameView); } // For new projects, show services window if and only if online and logged in if (newProjectLayoutWasCreated) { if (UnityConnect.instance.online && UnityConnect.instance.loggedIn && UnityConnect.instance.shouldShowServicesWindow) { UnityConnectServiceCollection.instance.ShowService(HubAccess.kServiceName, true, "new_project_created"); } else { UnityConnectServiceCollection.instance.CloseServices(); } } } catch (System.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 (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); }
public static void Unmaximize(EditorWindow win) { HostView maximizedHostView = win.m_Parent; if (maximizedHostView == null) { Debug.LogError("Host view was not found"); RevertFactorySettings(); return; } UnityObject[] newWindows = InternalEditorUtility.LoadSerializedFileAndForget(Path.Combine(layoutsProjectPath, kMaximizeRestoreFile)); if (newWindows.Length < 2) { Debug.Log("Maximized serialized file backup not found"); RevertFactorySettings(); return; } SplitView oldRoot = newWindows[0] as SplitView; EditorWindow oldWindow = newWindows[1] as EditorWindow; if (oldRoot == null) { Debug.Log("Maximization failed because the root split view was not found"); RevertFactorySettings(); return; } ContainerWindow parentWindow = win.m_Parent.window; if (parentWindow == null) { Debug.Log("Maximization failed because the root split view has no container window"); RevertFactorySettings(); return; } try { ContainerWindow.SetFreezeDisplay(true); // Put the loaded SplitView where the MaximizedHostView was if (maximizedHostView.parent) { int i = maximizedHostView.parent.IndexOfChild(maximizedHostView); Rect r = maximizedHostView.position; View parent = maximizedHostView.parent; parent.RemoveChild(i); parent.AddChild(oldRoot, i); oldRoot.position = r; // Move the Editor Window to the right spot in the DockArea newDockArea = oldWindow.m_Parent as DockArea; int oldDockAreaIndex = newDockArea.m_Panes.IndexOf(oldWindow); maximizedHostView.actualView = null; win.m_Parent = null; newDockArea.AddTab(oldDockAreaIndex, win); newDockArea.RemoveTab(oldWindow); UnityObject.DestroyImmediate(oldWindow); foreach (UnityObject o in newWindows) { EditorWindow curWin = o as EditorWindow; if (curWin != null) { curWin.MakeParentsSettingsMatchMe(); } } parent.Initialize(parent.window); //If parent window had to be resized, call this to make sure new size gets propagated parent.position = parent.position; oldRoot.Reflow(); } else { throw new System.Exception(); } // Kill the maximizedMainView UnityObject.DestroyImmediate(maximizedHostView); win.Focus(); parentWindow.DisplayAllViews(); win.m_Parent.MakeVistaDWMHappyDance(); } catch (System.Exception ex) { Debug.Log("Maximization failed: " + ex); RevertFactorySettings(); } try { // Weird bug on AMD graphic cards under OSX Lion: Sometimes when unmaximizing we get stray white rectangles. // work around that by issueing an extra repaint (case 438764) if (Application.platform == RuntimePlatform.OSXEditor && SystemInfo.operatingSystem.Contains("10.7") && SystemInfo.graphicsDeviceVendor.Contains("ATI")) { foreach (GUIView v in Resources.FindObjectsOfTypeAll(typeof(GUIView))) { v.Repaint(); } } } finally { ContainerWindow.SetFreezeDisplay(false); } }
internal void Show(UnityObject obj, Type[] requiredTypes, UnityObject objectBeingEdited, bool allowSceneObjects, List <int> allowedInstanceIDs = null, Action <UnityObject> onObjectSelectorClosed = null, Action <UnityObject> onObjectSelectedUpdated = null) { m_ObjectSelectorReceiver = null; m_AllowSceneObjects = allowSceneObjects; m_IsShowingAssets = true; m_SkipHiddenPackages = true; m_AllowedIDs = allowedInstanceIDs; m_ObjectBeingEdited = objectBeingEdited; m_LastSelectedInstanceId = obj?.GetInstanceID() ?? 0; m_SelectionCancelled = false; m_OnObjectSelectorClosed = onObjectSelectorClosed; m_OnObjectSelectorUpdated = onObjectSelectedUpdated; // Do not allow to show scene objects if the object being edited is persistent if (m_ObjectBeingEdited != null && EditorUtility.IsPersistent(m_ObjectBeingEdited)) { m_AllowSceneObjects = false; } // Set which tab should be visible at startup if (m_AllowSceneObjects) { if (obj != null) { if (typeof(Component).IsAssignableFrom(obj.GetType())) { obj = ((Component)obj).gameObject; } // Set the right tab visible (so we can see our selection) m_IsShowingAssets = EditorUtility.IsPersistent(obj); } else { foreach (var requiredType in requiredTypes) { m_IsShowingAssets &= (requiredType != typeof(GameObject) && !typeof(Component).IsAssignableFrom(requiredType)); } } } else { m_IsShowingAssets = true; } // Set member variables m_DelegateView = GUIView.current; // type filter requires unqualified names for built-in types, but will prioritize them over user types, so ensure user types are namespace-qualified if (m_RequiredTypes == null) { m_RequiredTypes = new string[requiredTypes.Length]; } for (int i = 0; i < requiredTypes.Length; i++) { if (requiredTypes[i] != null) { m_RequiredTypes[i] = typeof(ScriptableObject).IsAssignableFrom(requiredTypes[i]) || typeof(MonoBehaviour).IsAssignableFrom(requiredTypes[i]) ? requiredTypes[i].FullName : requiredTypes[i].Name; } } m_SearchFilter = ""; m_OriginalSelection = obj; m_ModalUndoGroup = Undo.GetCurrentGroup(); // Show custom selector if available if (ObjectSelectorSearch.HasEngineOverride()) { m_SearchSessionHandler.BeginSession(() => { return(new SearchService.ObjectSelectorSearchContext { currentObject = obj, editedObjects = m_EditedProperty != null ? m_EditedProperty.serializedObject.targetObjects : new[] { objectBeingEdited }, requiredTypes = requiredTypes, requiredTypeNames = m_RequiredTypes, allowedInstanceIds = allowedInstanceIDs, visibleObjects = allowSceneObjects ? SearchService.VisibleObjects.All : SearchService.VisibleObjects.Assets, }); }); Action <UnityObject> onSelectionChanged = selectedObj => { m_LastSelectedInstanceId = selectedObj == null ? 0 : selectedObj.GetInstanceID(); NotifySelectionChanged(false); }; Action <UnityObject, bool> onSelectorClosed = (selectedObj, canceled) => { m_SearchSessionHandler.EndSession(); if (canceled) { // Undo changes we have done in the ObjectSelector Undo.RevertAllDownToGroup(m_ModalUndoGroup); m_LastSelectedInstanceId = 0; m_SelectionCancelled = true; } else { m_LastSelectedInstanceId = selectedObj == null ? 0 : selectedObj.GetInstanceID(); NotifySelectionChanged(false); } m_EditedProperty = null; NotifySelectorClosed(false); }; if (m_SearchSessionHandler.SelectObject(onSelectorClosed, onSelectionChanged)) { return; } else { m_SearchSessionHandler.EndSession(); } } // Freeze to prevent flicker on OSX. // Screen will be updated again when calling // SetFreezeDisplay(false) further down. ContainerWindow.SetFreezeDisplay(true); var shouldRepositionWindow = m_Parent != null; ShowWithMode(ShowMode.AuxWindow); string text = "Select " + (requiredTypes[0] == null ? m_RequiredTypes[0] : requiredTypes[0].Name); for (int i = 1; i < requiredTypes.Length; i++) { text += (i == requiredTypes.Length - 1 ? " or " : ", ") + (requiredTypes[i] == null ? m_RequiredTypes[i] : requiredTypes[i].Name); } titleContent = EditorGUIUtility.TrTextContent(text); // Deal with window size if (shouldRepositionWindow) { m_Parent.window.LoadInCurrentMousePosition(); m_Parent.window.FitWindowToScreen(true); } Rect p = m_Parent == null ? new Rect(0, 0, 1, 1) : m_Parent.window.position; p.width = EditorPrefs.GetFloat("ObjectSelectorWidth", 200); p.height = EditorPrefs.GetFloat("ObjectSelectorHeight", 390); position = p; minSize = new Vector2(kMinWidth, kMinTopSize + kPreviewExpandedAreaHeight + 2 * kPreviewMargin); maxSize = new Vector2(10000, 10000); SetupPreview(); // Focus Focus(); ContainerWindow.SetFreezeDisplay(false); m_FocusSearchFilter = true; // Add after unfreezing display because AuxWindowManager.cpp assumes that aux windows are added after we get 'got/lost'- focus calls. if (m_Parent != null) { m_Parent.AddToAuxWindowList(); } // Initial selection int initialSelection = obj != null?obj.GetInstanceID() : 0; if (initialSelection != 0) { var assetPath = AssetDatabase.GetAssetPath(initialSelection); if (m_SkipHiddenPackages && !PackageManagerUtilityInternal.IsPathInVisiblePackage(assetPath)) { m_SkipHiddenPackages = false; } } if (m_RequiredTypes.All(t => ShouldTreeViewBeUsed(t))) { m_ObjectTreeWithSearch.Init(position, this, CreateAndSetTreeView, TreeViewSelection, ItemWasDoubleClicked, initialSelection, 0); } else { // To frame the selected item we need to wait to initialize the search until our window has been setup InitIfNeeded(); m_ListArea.InitSelection(new[] { initialSelection }); if (initialSelection != 0) { m_ListArea.Frame(initialSelection, true, false); } } }
internal void Show(UnityEngine.Object obj, Type requiredType, SerializedProperty property, bool allowSceneObjects, List <int> allowedInstanceIDs) { this.m_AllowSceneObjects = allowSceneObjects; this.m_IsShowingAssets = true; this.m_AllowedIDs = allowedInstanceIDs; string text = string.Empty; if (property != null) { text = property.objectReferenceTypeString; obj = property.objectReferenceValue; UnityEngine.Object targetObject = property.serializedObject.targetObject; if (targetObject != null && EditorUtility.IsPersistent(targetObject)) { this.m_AllowSceneObjects = false; } } else { if (requiredType != null) { text = requiredType.Name; } } if (this.m_AllowSceneObjects) { if (obj != null) { if (typeof(Component).IsAssignableFrom(obj.GetType())) { obj = ((Component)obj).gameObject; } this.m_IsShowingAssets = (EditorUtility.IsPersistent(obj) || ObjectSelector.GuessIfUserIsLookingForAnAsset(text, false)); } else { this.m_IsShowingAssets = ObjectSelector.GuessIfUserIsLookingForAnAsset(text, true); } } else { this.m_IsShowingAssets = true; } this.m_DelegateView = GUIView.current; this.m_RequiredType = text; this.m_SearchFilter = string.Empty; this.m_OriginalSelection = obj; this.m_ModalUndoGroup = Undo.GetCurrentGroup(); ContainerWindow.SetFreezeDisplay(true); base.ShowWithMode(ShowMode.AuxWindow); base.title = "Select " + text; Rect position = this.m_Parent.window.position; position.width = EditorPrefs.GetFloat("ObjectSelectorWidth", 200f); position.height = EditorPrefs.GetFloat("ObjectSelectorHeight", 390f); base.position = position; base.minSize = new Vector2(200f, 335f); base.maxSize = new Vector2(10000f, 10000f); this.SetupPreview(); base.Focus(); ContainerWindow.SetFreezeDisplay(false); this.m_FocusSearchFilter = true; this.m_Parent.AddToAuxWindowList(); int num = (!(obj != null)) ? 0 : obj.GetInstanceID(); if (property != null && property.hasMultipleDifferentValues) { num = 0; } if (ObjectSelector.ShouldTreeViewBeUsed(text)) { this.m_ObjectTreeWithSearch.Init(base.position, this, new UnityAction <ObjectTreeForSelector.TreeSelectorData>(this.CreateAndSetTreeView), new UnityAction <TreeViewItem>(this.TreeViewSelection), new UnityAction(this.ItemWasDoubleClicked), num, 0); } else { this.InitIfNeeded(); this.m_ListArea.InitSelection(new int[] { num }); if (num != 0) { this.m_ListArea.Frame(num, true, false); } } }
public static bool LoadWindowLayout(string path, bool newProjectLayoutWasCreated) { Rect position = default(Rect); UnityEngine.Object[] array = Resources.FindObjectsOfTypeAll(typeof(ContainerWindow)); UnityEngine.Object[] array2 = array; for (int i = 0; i < array2.Length; i++) { ContainerWindow containerWindow = (ContainerWindow)array2[i]; if (containerWindow.showMode == ShowMode.MainWindow) { position = containerWindow.position; } } try { ContainerWindow.SetFreezeDisplay(true); WindowLayout.CloseWindows(); UnityEngine.Object[] array3 = InternalEditorUtility.LoadSerializedFileAndForget(path); ContainerWindow containerWindow2 = null; ContainerWindow containerWindow3 = null; UnityEngine.Object[] array4 = array3; for (int j = 0; j < array4.Length; j++) { UnityEngine.Object @object = array4[j]; ContainerWindow containerWindow4 = @object as ContainerWindow; if (containerWindow4 != null && containerWindow4.showMode == ShowMode.MainWindow) { containerWindow3 = containerWindow4; if ((double)position.width != 0.0) { containerWindow2 = containerWindow4; containerWindow2.position = position; } } } int num = 0; UnityEngine.Object[] array5 = array3; for (int k = 0; k < array5.Length; k++) { UnityEngine.Object object2 = array5[k]; if (object2 == null) { UnityEngine.Debug.LogError("Error while reading window layout: window #" + num + " is null"); throw new Exception(); } if (object2.GetType() == null) { UnityEngine.Debug.LogError(string.Concat(new object[] { "Error while reading window layout: window #", num, " type is null, instanceID=", object2.GetInstanceID() })); throw new Exception(); } if (newProjectLayoutWasCreated) { MethodInfo method = object2.GetType().GetMethod("OnNewProjectLayoutWasCreated", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (method != null) { method.Invoke(object2, null); } } num++; } if (containerWindow2) { containerWindow2.position = position; containerWindow2.OnResize(); } if (containerWindow3 == null) { UnityEngine.Debug.LogError("Error while reading window layout: no main window found"); throw new Exception(); } containerWindow3.Show(containerWindow3.showMode, true, true); UnityEngine.Object[] array6 = array3; for (int l = 0; l < array6.Length; l++) { UnityEngine.Object object3 = array6[l]; EditorWindow editorWindow = object3 as EditorWindow; if (editorWindow) { editorWindow.minSize = editorWindow.minSize; } ContainerWindow containerWindow5 = object3 as ContainerWindow; if (containerWindow5 && containerWindow5 != containerWindow3) { containerWindow5.Show(containerWindow5.showMode, true, true); } } GameView gameView = WindowLayout.GetMaximizedWindow() as GameView; if (gameView != null && gameView.maximizeOnPlay) { WindowLayout.Unmaximize(gameView); } } catch (Exception arg) { UnityEngine.Debug.LogError("Failed to load window layout: " + arg); switch (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")) { case 0: WindowLayout.LoadDefaultLayout(); break; case 1: EditorApplication.Exit(0); break; case 2: WindowLayout.RevertFactorySettings(); break; } return(false); } finally { ContainerWindow.SetFreezeDisplay(false); if (Path.GetExtension(path) == ".wlt") { Toolbar.lastLoadedLayoutName = Path.GetFileNameWithoutExtension(path); } else { Toolbar.lastLoadedLayoutName = null; } } return(true); }
internal void Show(UnityObject obj, Type requiredType, SerializedProperty property, bool allowSceneObjects, List <int> allowedInstanceIDs, Action <UnityObject> onObjectSelectorClosed, Action <UnityObject> onObjectSelectedUpdated) { m_ObjectSelectorReceiver = null; m_AllowSceneObjects = allowSceneObjects; m_IsShowingAssets = true; m_SkipHiddenPackages = true; m_AllowedIDs = allowedInstanceIDs; m_OnObjectSelectorClosed = onObjectSelectorClosed; m_OnObjectSelectorUpdated = onObjectSelectedUpdated; if (property != null) { if (requiredType == null) { ScriptAttributeUtility.GetFieldInfoFromProperty(property, out requiredType); // case 951876: built-in types do not actually have reflectable fields, so their object types must be extracted from the type string // this works because built-in types will only ever have serialized references to other built-in types, which this window's filter expects as unqualified names if (requiredType == null) { m_RequiredType = s_MatchPPtrTypeName.Match(property.type).Groups[1].Value; } } obj = property.objectReferenceValue; m_ObjectBeingEdited = property.serializedObject.targetObject; // Do not allow to show scene objects if the object being edited is persistent if (m_ObjectBeingEdited != null && EditorUtility.IsPersistent(m_ObjectBeingEdited)) { m_AllowSceneObjects = false; } } // Set which tab should be visible at startup if (m_AllowSceneObjects) { if (obj != null) { if (typeof(Component).IsAssignableFrom(obj.GetType())) { obj = ((Component)obj).gameObject; } // Set the right tab visible (so we can see our selection) m_IsShowingAssets = EditorUtility.IsPersistent(obj); } else { m_IsShowingAssets = (requiredType != typeof(GameObject) && !typeof(Component).IsAssignableFrom(requiredType)); } } else { m_IsShowingAssets = true; } // Set member variables m_DelegateView = GUIView.current; // type filter requires unqualified names for built-in types, but will prioritize them over user types, so ensure user types are namespace-qualified if (requiredType != null) { m_RequiredType = typeof(ScriptableObject).IsAssignableFrom(requiredType) || typeof(MonoBehaviour).IsAssignableFrom(requiredType) ? requiredType.FullName : requiredType.Name; } m_SearchFilter = ""; m_OriginalSelection = obj; m_ModalUndoGroup = Undo.GetCurrentGroup(); // Freeze to prevent flicker on OSX. // Screen will be updated again when calling // SetFreezeDisplay(false) further down. ContainerWindow.SetFreezeDisplay(true); ShowWithMode(ShowMode.AuxWindow); titleContent = EditorGUIUtility.TrTextContent("Select " + (requiredType == null ? m_RequiredType : requiredType.Name)); // Deal with window size Rect p = m_Parent == null ? new Rect(0, 0, 1, 1) : m_Parent.window.position; p.width = EditorPrefs.GetFloat("ObjectSelectorWidth", 200); p.height = EditorPrefs.GetFloat("ObjectSelectorHeight", 390); position = p; minSize = new Vector2(kMinWidth, kMinTopSize + kPreviewExpandedAreaHeight + 2 * kPreviewMargin); maxSize = new Vector2(10000, 10000); SetupPreview(); // Focus Focus(); ContainerWindow.SetFreezeDisplay(false); m_FocusSearchFilter = true; // Add after unfreezing display because AuxWindowManager.cpp assumes that aux windows are added after we get 'got/lost'- focus calls. if (m_Parent != null) { m_Parent.AddToAuxWindowList(); } // Initial selection int initialSelection = obj != null?obj.GetInstanceID() : 0; if (property != null && property.hasMultipleDifferentValues) { initialSelection = 0; // don't select anything on multi selection } if (initialSelection != 0) { var assetPath = AssetDatabase.GetAssetPath(initialSelection); if (m_SkipHiddenPackages && !PackageManagerUtilityInternal.IsPathInVisiblePackage(assetPath)) { m_SkipHiddenPackages = false; } } if (ShouldTreeViewBeUsed(m_RequiredType)) { m_ObjectTreeWithSearch.Init(position, this, CreateAndSetTreeView, TreeViewSelection, ItemWasDoubleClicked, initialSelection, 0); } else { // To frame the selected item we need to wait to initialize the search until our window has been setup InitIfNeeded(); m_ListArea.InitSelection(new[] { initialSelection }); if (initialSelection != 0) { m_ListArea.Frame(initialSelection, true, false); } } }
internal void Show(UnityEngine.Object obj, Type requiredType, SerializedProperty property, bool allowSceneObjects, List <int> allowedInstanceIDs, Action <UnityEngine.Object> onObjectSelectorClosed, Action <UnityEngine.Object> onObjectSelectedUpdated) { this.m_ObjectSelectorReceiver = null; this.m_AllowSceneObjects = allowSceneObjects; this.m_IsShowingAssets = true; this.m_AllowedIDs = allowedInstanceIDs; this.m_OnObjectSelectorClosed = onObjectSelectorClosed; this.m_OnObjectSelectorUpdated = onObjectSelectedUpdated; if (property != null) { if (requiredType == null) { ScriptAttributeUtility.GetFieldInfoFromProperty(property, out requiredType); if (requiredType == null) { this.m_RequiredType = this.s_MatchPPtrTypeName.Match(property.type).Groups[1].Value; } } obj = property.objectReferenceValue; this.m_ObjectBeingEdited = property.serializedObject.targetObject; if (this.m_ObjectBeingEdited != null && EditorUtility.IsPersistent(this.m_ObjectBeingEdited)) { this.m_AllowSceneObjects = false; } } if (this.m_AllowSceneObjects) { if (obj != null) { if (typeof(Component).IsAssignableFrom(obj.GetType())) { obj = ((Component)obj).gameObject; } this.m_IsShowingAssets = EditorUtility.IsPersistent(obj); } else { this.m_IsShowingAssets = (requiredType != typeof(GameObject) && !typeof(Component).IsAssignableFrom(requiredType)); } } else { this.m_IsShowingAssets = true; } this.m_DelegateView = GUIView.current; if (requiredType != null) { this.m_RequiredType = ((!typeof(ScriptableObject).IsAssignableFrom(requiredType) && !typeof(MonoBehaviour).IsAssignableFrom(requiredType)) ? requiredType.Name : requiredType.FullName); } this.m_SearchFilter = ""; this.m_OriginalSelection = obj; this.m_ModalUndoGroup = Undo.GetCurrentGroup(); ContainerWindow.SetFreezeDisplay(true); base.ShowWithMode(ShowMode.AuxWindow); base.titleContent = EditorGUIUtility.TrTextContent("Select " + ((requiredType != null) ? requiredType.Name : this.m_RequiredType), null, null); Rect position = this.m_Parent.window.position; position.width = EditorPrefs.GetFloat("ObjectSelectorWidth", 200f); position.height = EditorPrefs.GetFloat("ObjectSelectorHeight", 390f); base.position = position; base.minSize = new Vector2(200f, 335f); base.maxSize = new Vector2(10000f, 10000f); this.SetupPreview(); base.Focus(); ContainerWindow.SetFreezeDisplay(false); this.m_FocusSearchFilter = true; this.m_Parent.AddToAuxWindowList(); int num = (!(obj != null)) ? 0 : obj.GetInstanceID(); if (property != null && property.hasMultipleDifferentValues) { num = 0; } if (ObjectSelector.ShouldTreeViewBeUsed(requiredType)) { this.m_ObjectTreeWithSearch.Init(base.position, this, new UnityAction <ObjectTreeForSelector.TreeSelectorData>(this.CreateAndSetTreeView), new UnityAction <TreeViewItem>(this.TreeViewSelection), new UnityAction(this.ItemWasDoubleClicked), num, 0); } else { this.InitIfNeeded(); this.m_ListArea.InitSelection(new int[] { num }); if (num != 0) { this.m_ListArea.Frame(num, true, false); } } }
public static void Unmaximize(EditorWindow win) { HostView parent = win.m_Parent; if (parent == null) { UnityEngine.Debug.LogError("Host view was not found"); RevertFactorySettings(); } else { UnityEngine.Object[] objArray = InternalEditorUtility.LoadSerializedFileAndForget(Path.Combine(layoutsProjectPath, "CurrentMaximizeLayout.dwlt")); if (objArray.Length < 2) { UnityEngine.Debug.Log("Maximized serialized file backup not found"); RevertFactorySettings(); } else { SplitView child = objArray[0] as SplitView; EditorWindow item = objArray[1] as EditorWindow; if (child == null) { UnityEngine.Debug.Log("Maximization failed because the root split view was not found"); RevertFactorySettings(); } else { ContainerWindow window = win.m_Parent.window; if (window == null) { UnityEngine.Debug.Log("Maximization failed because the root split view has no container window"); RevertFactorySettings(); } else { try { ContainerWindow.SetFreezeDisplay(true); if (parent.parent == null) { throw new Exception(); } int idx = parent.parent.IndexOfChild(parent); Rect position = parent.position; View view3 = parent.parent; view3.RemoveChild(idx); view3.AddChild(child, idx); child.position = position; DockArea area = item.m_Parent as DockArea; int index = area.m_Panes.IndexOf(item); parent.actualView = null; win.m_Parent = null; area.AddTab(index, win); area.RemoveTab(item); UnityEngine.Object.DestroyImmediate(item); foreach (UnityEngine.Object obj2 in objArray) { EditorWindow window3 = obj2 as EditorWindow; if (window3 != null) { window3.MakeParentsSettingsMatchMe(); } } view3.Initialize(view3.window); view3.position = view3.position; child.Reflow(); UnityEngine.Object.DestroyImmediate(parent); win.Focus(); window.DisplayAllViews(); win.m_Parent.MakeVistaDWMHappyDance(); } catch (Exception exception) { UnityEngine.Debug.Log("Maximization failed: " + exception); RevertFactorySettings(); } try { if (((Application.platform == RuntimePlatform.OSXEditor) && SystemInfo.operatingSystem.Contains("10.7")) && SystemInfo.graphicsDeviceVendor.Contains("ATI")) { foreach (GUIView view4 in UnityEngine.Resources.FindObjectsOfTypeAll(typeof(GUIView))) { view4.Repaint(); } } } finally { ContainerWindow.SetFreezeDisplay(false); } } } } } }
public static bool LoadWindowLayout(string path, bool newProjectLayoutWasCreated) { Rect position = new Rect(); UnityEngine.Object[] objArray = UnityEngine.Resources.FindObjectsOfTypeAll(typeof(ContainerWindow)); foreach (ContainerWindow window in objArray) { if (window.showMode == ShowMode.MainWindow) { position = window.position; } } try { ContainerWindow.SetFreezeDisplay(true); CloseWindows(); UnityEngine.Object[] objArray3 = InternalEditorUtility.LoadSerializedFileAndForget(path); List<UnityEngine.Object> list = new List<UnityEngine.Object>(); for (int i = 0; i < objArray3.Length; i++) { UnityEngine.Object item = objArray3[i]; EditorWindow window2 = item as EditorWindow; if (window2 != null) { if (window2.m_Parent == null) { UnityEngine.Object.DestroyImmediate(window2, true); UnityEngine.Debug.LogError(string.Concat(new object[] { "Removed unparented EditorWindow while reading window layout: window #", i, ", type=", item.GetType().ToString(), ", instanceID=", item.GetInstanceID() })); continue; } } else { DockArea area = item as DockArea; if ((area != null) && (area.m_Panes.Count == 0)) { area.Close(null); UnityEngine.Debug.LogError(string.Concat(new object[] { "Removed empty DockArea while reading window layout: window #", i, ", instanceID=", item.GetInstanceID() })); continue; } } list.Add(item); } ContainerWindow window3 = null; ContainerWindow window4 = null; for (int j = 0; j < list.Count; j++) { ContainerWindow window5 = list[j] as ContainerWindow; if ((window5 != null) && (window5.showMode == ShowMode.MainWindow)) { window4 = window5; if (position.width != 0.0) { window3 = window5; window3.position = position; } } } for (int k = 0; k < list.Count; k++) { UnityEngine.Object obj3 = list[k]; if (obj3 == null) { UnityEngine.Debug.LogError("Error while reading window layout: window #" + k + " is null"); } else if (obj3.GetType() == null) { UnityEngine.Debug.LogError(string.Concat(new object[] { "Error while reading window layout: window #", k, " type is null, instanceID=", obj3.GetInstanceID() })); } else if (newProjectLayoutWasCreated) { MethodInfo method = obj3.GetType().GetMethod("OnNewProjectLayoutWasCreated", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); if (method != null) { method.Invoke(obj3, null); } } } if (window3 != null) { window3.position = position; window3.OnResize(); } if (window4 == null) { UnityEngine.Debug.LogError("Error while reading window layout: no main window found"); throw new Exception(); } window4.Show(window4.showMode, true, true); for (int m = 0; m < list.Count; m++) { EditorWindow window6 = list[m] as EditorWindow; if (window6 != null) { window6.minSize = window6.minSize; } ContainerWindow window7 = list[m] as ContainerWindow; if ((window7 != null) && (window7 != window4)) { window7.Show(window7.showMode, true, true); } } GameView maximizedWindow = GetMaximizedWindow() as GameView; if ((maximizedWindow != null) && maximizedWindow.maximizeOnPlay) { Unmaximize(maximizedWindow); } if (newProjectLayoutWasCreated) { if ((UnityConnect.instance.online && UnityConnect.instance.loggedIn) && UnityConnect.instance.shouldShowServicesWindow) { UnityConnectServiceCollection.instance.ShowService("Hub", true); } else { UnityConnectServiceCollection.instance.CloseServices(); } } } catch (Exception exception) { UnityEngine.Debug.LogError("Failed to load window layout: " + exception); int num6 = 0; if (!Application.isTestRun) { num6 = 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"); } if (num6 == 0) { LoadDefaultLayout(); } else if (num6 == 1) { EditorApplication.Exit(0); } else if (num6 == 2) { RevertFactorySettings(); } return false; } finally { ContainerWindow.SetFreezeDisplay(false); if (Path.GetExtension(path) == ".wlt") { Toolbar.lastLoadedLayoutName = Path.GetFileNameWithoutExtension(path); } else { Toolbar.lastLoadedLayoutName = null; } } return true; }
public static bool LoadWindowLayout(string path, bool newProjectLayoutWasCreated) { Rect rect = new Rect(); foreach (ContainerWindow containerWindow in Resources.FindObjectsOfTypeAll(typeof(ContainerWindow))) { if (containerWindow.showMode == ShowMode.MainWindow) { rect = containerWindow.position; } } try { ContainerWindow.SetFreezeDisplay(true); WindowLayout.CloseWindows(); UnityEngine.Object[] objectArray = InternalEditorUtility.LoadSerializedFileAndForget(path); ContainerWindow containerWindow1 = (ContainerWindow)null; ContainerWindow containerWindow2 = (ContainerWindow)null; foreach (UnityEngine.Object @object in objectArray) { ContainerWindow containerWindow3 = @object as ContainerWindow; if ((UnityEngine.Object)containerWindow3 != (UnityEngine.Object)null && containerWindow3.showMode == ShowMode.MainWindow) { containerWindow2 = containerWindow3; if ((double)rect.width != 0.0) { containerWindow1 = containerWindow3; containerWindow1.position = rect; } } } int num = 0; foreach (UnityEngine.Object @object in objectArray) { if (@object == (UnityEngine.Object)null) { UnityEngine.Debug.LogError((object)("Error while reading window layout: window #" + (object)num + " is null")); throw new Exception(); } if (@object.GetType() == null) { UnityEngine.Debug.LogError((object)("Error while reading window layout: window #" + (object)num + " type is null, instanceID=" + (object)@object.GetInstanceID())); throw new Exception(); } if (newProjectLayoutWasCreated) { MethodInfo method = @object.GetType().GetMethod("OnNewProjectLayoutWasCreated", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (method != null) { method.Invoke((object)@object, (object[])null); } } ++num; } if ((bool)((UnityEngine.Object)containerWindow1)) { containerWindow1.position = rect; containerWindow1.OnResize(); } if ((UnityEngine.Object)containerWindow2 == (UnityEngine.Object)null) { UnityEngine.Debug.LogError((object)"Error while reading window layout: no main window found"); throw new Exception(); } containerWindow2.Show(containerWindow2.showMode, true, true); foreach (UnityEngine.Object @object in objectArray) { EditorWindow editorWindow = @object as EditorWindow; if ((bool)((UnityEngine.Object)editorWindow)) { editorWindow.minSize = editorWindow.minSize; } ContainerWindow containerWindow3 = @object as ContainerWindow; if ((bool)((UnityEngine.Object)containerWindow3) && (UnityEngine.Object)containerWindow3 != (UnityEngine.Object)containerWindow2) { containerWindow3.Show(containerWindow3.showMode, true, true); } } GameView maximizedWindow = WindowLayout.GetMaximizedWindow() as GameView; if ((UnityEngine.Object)maximizedWindow != (UnityEngine.Object)null) { if (maximizedWindow.maximizeOnPlay) { WindowLayout.Unmaximize((EditorWindow)maximizedWindow); } } } catch (Exception ex) { UnityEngine.Debug.LogError((object)("Failed to load window layout: " + (object)ex)); switch (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")) { case 0: WindowLayout.LoadDefaultLayout(); break; case 1: EditorApplication.Exit(0); break; case 2: WindowLayout.RevertFactorySettings(); break; } return(false); } finally { ContainerWindow.SetFreezeDisplay(false); Toolbar.lastLoadedLayoutName = !(Path.GetExtension(path) == ".wlt") ? (string)null : Path.GetFileNameWithoutExtension(path); } return(true); }
public static void Unmaximize(EditorWindow win) { HostView parent1 = win.m_Parent; if ((UnityEngine.Object)parent1 == (UnityEngine.Object)null) { UnityEngine.Debug.LogError((object)"Host view was not found"); WindowLayout.RevertFactorySettings(); } else { UnityEngine.Object[] objectArray = InternalEditorUtility.LoadSerializedFileAndForget(Path.Combine(WindowLayout.layoutsProjectPath, "CurrentMaximizeLayout.dwlt")); if (objectArray.Length < 2) { UnityEngine.Debug.Log((object)"Maximized serialized file backup not found"); WindowLayout.RevertFactorySettings(); } else { SplitView splitView = objectArray[0] as SplitView; EditorWindow pane = objectArray[1] as EditorWindow; if ((UnityEngine.Object)splitView == (UnityEngine.Object)null) { UnityEngine.Debug.Log((object)"Maximization failed because the root split view was not found"); WindowLayout.RevertFactorySettings(); } else { ContainerWindow window = win.m_Parent.window; if ((UnityEngine.Object)window == (UnityEngine.Object)null) { UnityEngine.Debug.Log((object)"Maximization failed because the root split view has no container window"); WindowLayout.RevertFactorySettings(); } else { try { ContainerWindow.SetFreezeDisplay(true); if (!(bool)((UnityEngine.Object)parent1.parent)) { throw new Exception(); } int idx1 = parent1.parent.IndexOfChild((View)parent1); Rect position = parent1.position; View parent2 = parent1.parent; parent2.RemoveChild(idx1); parent2.AddChild((View)splitView, idx1); splitView.position = position; DockArea parent3 = pane.m_Parent as DockArea; int idx2 = parent3.m_Panes.IndexOf(pane); parent1.actualView = (EditorWindow)null; win.m_Parent = (HostView)null; parent3.AddTab(idx2, win); parent3.RemoveTab(pane); UnityEngine.Object.DestroyImmediate((UnityEngine.Object)pane); foreach (UnityEngine.Object @object in objectArray) { EditorWindow editorWindow = @object as EditorWindow; if ((UnityEngine.Object)editorWindow != (UnityEngine.Object)null) { editorWindow.MakeParentsSettingsMatchMe(); } } parent2.Initialize(parent2.window); parent2.position = parent2.position; splitView.Reflow(); UnityEngine.Object.DestroyImmediate((UnityEngine.Object)parent1); win.Focus(); window.DisplayAllViews(); win.m_Parent.MakeVistaDWMHappyDance(); } catch (Exception ex) { UnityEngine.Debug.Log((object)("Maximization failed: " + (object)ex)); WindowLayout.RevertFactorySettings(); } try { if (Application.platform != RuntimePlatform.OSXEditor || !SystemInfo.operatingSystem.Contains("10.7") || !SystemInfo.graphicsDeviceVendor.Contains("ATI")) { return; } foreach (GUIView guiView in Resources.FindObjectsOfTypeAll(typeof(GUIView))) { guiView.Repaint(); } } finally { ContainerWindow.SetFreezeDisplay(false); } } } } } }