private static void OnModeChangeLayouts(ModeChangedArgs args) { // Prevent double loading the default/last layout already done by the WindowLayout system. if (args.prevIndex == -1) { return; } if (HasCapability(ModeCapability.LayoutSwitching, true)) { WindowLayout.SaveCurrentLayoutPerMode(GetModeId(args.prevIndex)); try { if (args.nextIndex != 0 || args.prevIndex == -1 || HasCapability(args.prevIndex, ModeCapability.LayoutSwitching, true)) { // Load the last valid layout for this mode WindowLayout.LoadCurrentModeLayout(keepMainWindow: true); } } catch (Exception) { // Error while loading layout. Load the default layout for current mode. WindowLayout.LoadDefaultLayout(); } } if (HasCapability(ModeCapability.LayoutWindowMenu, true)) { WindowLayout.ReloadWindowLayoutMenu(); EditorUtility.Internal_UpdateAllMenus(); } }
internal static void RaiseModeChanged(int prevIndex, int nextIndex) { modeChanged?.Invoke(new ModeChangedArgs { prevIndex = prevIndex, nextIndex = nextIndex }); EditorUtility.Internal_UpdateAllMenus(); }
internal static void BuildWindowMenuListing() { const string k_RootMenuItemName = "Window/Panels"; Menu.RemoveMenuItem(k_RootMenuItemName); var editorWindows = Resources.FindObjectsOfTypeAll <EditorWindow>(); int menuIdx = -10; Menu.AddMenuItem($"{k_RootMenuItemName}/Close all floating panels...", "", false, menuIdx++, () => { var windows = Resources.FindObjectsOfTypeAll <ContainerWindow>(); foreach (var win in windows.Where(w => !!w && w.showMode != ShowMode.MainWindow)) { win.Close(); } }, null); Menu.AddSeparator($"{k_RootMenuItemName}/", menuIdx++); int menuIndex = 1; foreach (var win in editorWindows.Where(e => !!e).OrderBy(e => e.titleContent.text)) { var title = win.titleContent.text; if (!String.IsNullOrEmpty(win.titleContent.tooltip) && win.titleContent.tooltip != title) { title = win.titleContent.tooltip; } title = title.Replace("/", "\\"); Menu.AddMenuItem($"{k_RootMenuItemName}/{menuIndex++} {title}", "", false, menuIdx++, () => win.Focus(), null); } EditorUtility.Internal_UpdateAllMenus(); }
void OnGUI() { if (m_Paths == null) { InitializePaths(); } m_ScrollPos = EditorGUILayout.BeginScrollView(m_ScrollPos); foreach (string path in m_Paths) { string name = Path.GetFileNameWithoutExtension(path); if (name.Length > k_MaxLayoutNameLength) { name = name.Substring(0, k_MaxLayoutNameLength) + "..."; } if (GUILayout.Button(name)) { if (Toolbar.lastLoadedLayoutName == name) { Toolbar.lastLoadedLayoutName = null; } File.Delete(path); WindowLayout.ReloadWindowLayoutMenu(); EditorUtility.Internal_UpdateAllMenus(); ShortcutIntegration.instance.RebuildShortcuts(); InitializePaths(); } } EditorGUILayout.EndScrollView(); }
static WindowLayout() { EditorApplication.delayCall += () => { ReloadWindowLayoutMenu(); EditorUtility.Internal_UpdateAllMenus(); }; }
void OnGUI() { GUILayout.Space(5); Event evt = Event.current; bool hitEnter = evt.type == EventType.KeyDown && (evt.keyCode == KeyCode.Return || evt.keyCode == KeyCode.KeypadEnter); GUI.SetNextControlName("m_PreferencesName"); EditorGUI.BeginChangeCheck(); s_LayoutName = EditorGUILayout.TextField(s_LayoutName); if (EditorGUI.EndChangeCheck()) { UpdateCurrentInvalidChars(); } if (!m_DidFocus) { m_DidFocus = true; EditorGUI.FocusTextInControl("m_PreferencesName"); } if (s_CurrentInvalidChars.Length != 0) { EditorGUILayout.HelpBox(string.Format(s_InvalidCharsFormatString, s_CurrentInvalidChars), MessageType.Warning); minSize = new Vector2(k_Width, k_Height + k_HelpBoxHeight); } else { minSize = new Vector2(k_Width, k_Height); } bool canSaveLayout = s_LayoutName.Length > 0 && s_CurrentInvalidChars.Length == 0; EditorGUI.BeginDisabled(!canSaveLayout); if (GUILayout.Button("Save") || hitEnter && canSaveLayout) { Close(); if (!Directory.Exists(WindowLayout.layoutsModePreferencesPath)) { Directory.CreateDirectory(WindowLayout.layoutsModePreferencesPath); } string path = Path.Combine(WindowLayout.layoutsModePreferencesPath, s_LayoutName + ".wlt"); Toolbar.lastLoadedLayoutName = s_LayoutName; WindowLayout.SaveWindowLayout(path); WindowLayout.ReloadWindowLayoutMenu(); EditorUtility.Internal_UpdateAllMenus(); ShortcutIntegration.instance.RebuildShortcuts(); GUIUtility.ExitGUI(); } else { m_DidFocus = false; } EditorGUI.EndDisabled(); }
internal static void RaiseModeChanged(int prevIndex, int nextIndex) { modeChanged?.Invoke(new ModeChangedArgs { prevIndex = prevIndex, nextIndex = nextIndex }); // Not required when you start the editor in the default mode. if (prevIndex != -1 || nextIndex != 0) { EditorUtility.Internal_UpdateAllMenus(); ShortcutIntegration.instance.RebuildShortcuts(); } }
internal static void RefreshMenus() { Menu.ResetMenus(true); UpdateModeMenus(currentIndex); EditorUtility.Internal_UpdateAllMenus(); }