public static void DisplayPopupMenu(Rect position, string menuItemPath, MenuCommand command) { if (ModeService.HasContextMenu(menuItemPath)) { ModeService.PopupContextMenu(menuItemPath); } else { // Validate input. Fixes case 406024: 'Custom context menu in a custom window crashes Unity' if (menuItemPath == "CONTEXT" || menuItemPath == "CONTEXT/" || menuItemPath == "CONTEXT\\") { bool error = command == null || command.context == null; if (error) { Debug.LogError("DisplayPopupMenu: invalid arguments: using CONTEXT requires a valid MenuCommand object. If you want a custom context menu then try using the GenericMenu."); return; } } Vector2 temp = GUIUtility.GUIToScreenPoint(new Vector2(position.x, position.y)); position.x = temp.x; position.y = temp.y; Internal_DisplayPopupMenu(position, menuItemPath, command?.context, command?.userData ?? 0); } ResetMouseDown(); }
static void FireFileMenuNewScene() { if (!ModeService.Execute("file_new_scene")) { FileMenuNewScene(); } }
static void SetupProfiledConnection(int connId) { ProfilerDriver.connectedProfiler = ProfilerDriver.GetAvailableProfilers().FirstOrDefault(id => id == connId); ModeService.RefreshMenus(); Menu.SetChecked("Edit/Record", s_SlaveProfilerWindow.IsRecording()); Menu.SetChecked("Edit/Deep Profiling", ProfilerDriver.deepProfiling); EditorApplication.UpdateMainWindowTitle(); s_SlaveProfilerWindow.Repaint(); }
private static IEnumerable <Type> GetDefaultPaneTypes() { const string k_PaneTypesSectionName = "pane_types"; if (!ModeService.HasSection(ModeService.currentIndex, k_PaneTypesSectionName)) { return(k_PaneTypes); } return(GetCurrentModePaneTypes(k_PaneTypesSectionName)); }
public void OnEnable() { prevSizeGroupType = (int)currentSizeGroupType; titleContent = GetLocalizedTitleContent(); UpdateZoomAreaAndParent(); showToolbar = ModeService.HasCapability(ModeCapability.GameViewToolbar, true); ModeService.modeChanged += OnEditorModeChanged; EditorApplication.playModeStateChanged += OnPlayModeStateChanged; }
private static IEnumerable <Type> GetDefaultPaneTypes() { const string k_PaneTypesSectionName = "pane_types"; if (!ModeService.HasSection(ModeService.currentIndex, k_PaneTypesSectionName)) { return(k_PaneTypes); } var modePaneTypes = ModeService.GetModeDataSectionList <string>(ModeService.currentIndex, k_PaneTypesSectionName).ToList(); return(TypeCache.GetTypesDerivedFrom <EditorWindow>().Where(t => modePaneTypes.Any(mpt => t.Name.EndsWith(mpt))).ToArray()); }
protected override void OnEnable() { base.OnEnable(); s_AppStatusBar = this; m_autoLightBakingOn = GetBakeMode(); m_ManagedDebuggerToggle = new ManagedDebuggerToggle(); m_CacheServerToggle = new CacheServerToggle(); m_EventInterests.wantsLessLayoutEvents = true; m_DrawExtraFeatures = ModeService.HasCapability(ModeCapability.StatusBarExtraFeatures, true); Progress.added += RefreshProgressBar; Progress.removed += RefreshProgressBar; Progress.updated += RefreshProgressBar; }
private static IEnumerable <Type> GetCurrentModePaneTypes(string modePaneTypeSectionName) { var modePaneTypes = ModeService.GetModeDataSectionList <string>(ModeService.currentIndex, modePaneTypeSectionName); var editorWindowTypes = TypeCache.GetTypesDerivedFrom <EditorWindow>(); foreach (var paneTypeName in modePaneTypes) { var paneType = editorWindowTypes.FirstOrDefault(t => t.Name.EndsWith(paneTypeName)); if (paneType != null) { yield return(paneType); } else { Debug.LogWarning($"Cannot find editor window pane type {paneTypeName} for editor mode {ModeService.currentId}."); } } }
static void SetupProfilerDriver() { EditorApplication.update -= SetupProfilerDriver; if (s_ProfilerDriverSetup) return; ProfilerDriver.profileEditor = ProfilerUserSettings.defaultTargetMode == ProfilerEditorTargetMode.Editmode; var playerConnectionInfo = new PlayerConnectionInfo { recording = ProfilerDriver.enabled, profileEditor = ProfilerDriver.profileEditor }; if (!SessionState.GetBool("OOPP.PlayerConnectionOpened", false)) EventService.Request(nameof(EventType.UmpProfilerOpenPlayerConnection), HandlePlayerConnectionOpened, playerConnectionInfo, 5000L); s_ProfilerDriverSetup = true; ModeService.RefreshMenus(); }
internal static void ReloadWindowLayoutMenu() { Menu.RemoveMenuItem("Window/Layouts"); int layoutMenuItemPriority = 20; // Get user saved layouts if (Directory.Exists(layoutsModePreferencesPath)) { var layoutPaths = Directory.GetFiles(layoutsModePreferencesPath).Where(path => path.EndsWith(".wlt")).ToArray(); foreach (var layoutPath in layoutPaths) { var name = Path.GetFileNameWithoutExtension(layoutPath); Menu.AddMenuItem("Window/Layouts/" + name, "", false, layoutMenuItemPriority++, () => LoadWindowLayout(layoutPath, false), null); } layoutMenuItemPriority += 500; } // Get mode layouts var modeLayoutPaths = ModeService.GetModeDataSection(ModeService.currentIndex, ModeService.k_LayoutsSectionName) as IList <object>; if (modeLayoutPaths != null) { foreach (var layoutPath in modeLayoutPaths.Cast <string>()) { if (!File.Exists(layoutPath)) { continue; } var name = Path.GetFileNameWithoutExtension(layoutPath); Menu.AddMenuItem("Window/Layouts/" + name, "", Toolbar.lastLoadedLayoutName == name, layoutMenuItemPriority++, () => LoadWindowLayout(layoutPath, false), null); } } layoutMenuItemPriority += 500; Menu.AddMenuItem("Window/Layouts/Save Layout...", "", false, layoutMenuItemPriority++, SaveGUI, null); Menu.AddMenuItem("Window/Layouts/Delete Layout...", "", false, layoutMenuItemPriority++, DeleteGUI, null); Menu.AddMenuItem("Window/Layouts/Revert Factory Settings...", "", false, layoutMenuItemPriority++, () => RevertFactorySettings(false), null); }
protected Type[] GetPaneTypes() { const string k_PaneTypesSectionName = "pane_types"; if (!ModeService.HasSection(ModeService.currentIndex, k_PaneTypesSectionName)) { return new[] { typeof(SceneView), typeof(GameView), typeof(InspectorWindow), typeof(SceneHierarchyWindow), typeof(ProjectBrowser), typeof(ProfilerWindow), typeof(AnimationWindow) } } ; var modePaneTypes = ModeService.GetModeDataSectionList <string>(ModeService.currentIndex, k_PaneTypesSectionName).ToArray(); return(EditorAssemblies.SubclassesOf(typeof(EditorWindow)).Where(t => modePaneTypes.Any(mpt => t.Name.EndsWith(mpt))).ToArray()); }
internal static void BuildWindowMenuListing() { if (!ModeService.HasCapability(ModeCapability.LayoutWindowMenu, true)) { return; } 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); } }
public static void DelayLoadMode() { EditorApplication.update -= DelayLoadMode; ModeService.Refresh(null); }
private void OnEditorModeChanged(ModeService.ModeChangedArgs args) { showToolbar = ModeService.HasCapability(ModeCapability.GameViewToolbar, true); Repaint(); }
public override void OnGUI() { const float space = 8; const float standardButtonWidth = 32; const float dropdownWidth = 80; const float playPauseStopWidth = 140; const float previewPackagesinUseWidth = 173; const float previewPackagesinUseIconWidth = 45; InitializeToolIcons(); bool isOrWillEnterPlaymode = EditorApplication.isPlayingOrWillChangePlaymode; GUI.color = isOrWillEnterPlaymode ? HostView.kPlayModeDarken : Color.white; if (Event.current.type == EventType.Repaint) { Styles.appToolbar.Draw(new Rect(0, 0, position.width, position.height), false, false, false, false); } // Position left aligned controls controls - start from left to right. Rect pos = new Rect(0, 0, 0, 0); ReserveWidthRight(space, ref pos); ReserveWidthRight(standardButtonWidth * s_ShownToolIcons.Length, ref pos); DoToolButtons(EditorToolGUI.GetThickArea(pos)); ReserveWidthRight(space, ref pos); int playModeControlsStart = Mathf.RoundToInt((position.width - playPauseStopWidth) / 2); pos.x += pos.width; const float pivotButtonsWidth = 128; pos.width = pivotButtonsWidth; DoToolSettings(EditorToolGUI.GetThickArea(pos)); pos.width = pivotButtonsWidth; ReserveWidthRight(standardButtonWidth, ref pos); DoSnapButtons(EditorToolGUI.GetThickArea(pos)); // Position centered controls. pos = new Rect(playModeControlsStart, 0, 240, 0); if (ModeService.HasCapability(ModeCapability.Playbar, true)) { GUILayout.BeginArea(EditorToolGUI.GetThickArea(pos)); GUILayout.BeginHorizontal(); { if (!ModeService.Execute("gui_playbar", isOrWillEnterPlaymode)) { DoPlayButtons(isOrWillEnterPlaymode); } } GUILayout.EndHorizontal(); GUILayout.EndArea(); } // Position right aligned controls controls - start from right to left. pos = new Rect(position.width, 0, 0, 0); // Right spacing side ReserveWidthLeft(space, ref pos); ReserveWidthLeft(dropdownWidth, ref pos); if (ModeService.HasCapability(ModeCapability.LayoutWindowMenu, true)) { DoLayoutDropDown(EditorToolGUI.GetThinArea(pos)); } if (ModeService.HasCapability(ModeCapability.Layers, true)) { ReserveWidthLeft(space, ref pos); ReserveWidthLeft(dropdownWidth, ref pos); DoLayersDropDown(EditorToolGUI.GetThinArea(pos)); } if (UnityEditor.MPE.ProcessService.level == UnityEditor.MPE.ProcessLevel.Master) { ReserveWidthLeft(space, ref pos); ReserveWidthLeft(dropdownWidth, ref pos); if (EditorGUI.DropdownButton(EditorToolGUI.GetThinArea(pos), s_AccountContent, FocusType.Passive, Styles.dropdown)) { ShowUserMenu(EditorToolGUI.GetThinArea(pos)); } ReserveWidthLeft(space, ref pos); ReserveWidthLeft(standardButtonWidth, ref pos); if (GUI.Button(EditorToolGUI.GetThinArea(pos), s_CloudIcon, Styles.command)) { ServicesEditorWindow.ShowServicesWindow(); } } foreach (SubToolbar subToolbar in s_SubToolbars) { ReserveWidthLeft(space, ref pos); ReserveWidthLeft(subToolbar.Width, ref pos); subToolbar.OnGUI(EditorToolGUI.GetThinArea(pos)); } if (Unsupported.IsDeveloperBuild() && ModeService.hasSwitchableModes) { EditorGUI.BeginChangeCheck(); ReserveWidthLeft(space, ref pos); ReserveWidthLeft(dropdownWidth, ref pos); var selectedModeIndex = EditorGUI.Popup(EditorToolGUI.GetThinArea(pos), ModeService.currentIndex, ModeService.modeNames, Styles.dropdown); if (EditorGUI.EndChangeCheck()) { EditorApplication.delayCall += () => ModeService.ChangeModeByIndex(selectedModeIndex); GUIUtility.ExitGUI(); } } if (m_IsPreviewPackagesInUse && !m_PackageManagerPrefs.dismissPreviewPackagesInUse) { ReserveWidthLeft(space, ref pos); var useIcon = Toolbar.get.mainToolbar.position.width < k_MinWidthChangePreviewPackageInUseToIcon; ReserveWidthLeft(useIcon ? previewPackagesinUseIconWidth : previewPackagesinUseWidth, ref pos); var dropDownCustomColor = new GUIStyle(Styles.previewPackageInUseDropdown); if (EditorGUI.DropdownButton(EditorToolGUI.GetThinArea(pos), useIcon ? s_PreviewPackageIcon : s_PreviewPackageContent, FocusType.Passive, dropDownCustomColor)) { ShowPreviewPackageInUseMenu(EditorToolGUI.GetThinArea(pos)); } } EditorGUI.ShowRepaints(); }
protected override void OldOnGUI() { const float space = 10; const float largeSpace = 20; const float standardButtonWidth = 32; const float dropdownWidth = 80; const float playPauseStopWidth = 140; InitializeToolIcons(); bool isOrWillEnterPlaymode = EditorApplication.isPlayingOrWillChangePlaymode; GUI.color = isOrWillEnterPlaymode ? HostView.kPlayModeDarken : Color.white; if (Event.current.type == EventType.Repaint) { Styles.appToolbar.Draw(new Rect(0, 0, position.width, position.height), false, false, false, false); } // Position left aligned controls controls - start from left to right. Rect pos = new Rect(0, 0, 0, 0); ReserveWidthRight(space, ref pos); ReserveWidthRight(standardButtonWidth * s_ShownToolIcons.Length, ref pos); DoToolButtons(EditorToolGUI.GetThickArea(pos)); ReserveWidthRight(largeSpace, ref pos); int playModeControlsStart = Mathf.RoundToInt((position.width - playPauseStopWidth) / 2); pos.x += pos.width; pos.width = (playModeControlsStart - pos.x) - largeSpace; DoToolSettings(EditorToolGUI.GetThickArea(pos)); // Position centered controls. pos = new Rect(playModeControlsStart, 0, 240, 0); if (ModeService.HasCapability(ModeCapability.Playbar, true)) { GUILayout.BeginArea(EditorToolGUI.GetThickArea(pos)); GUILayout.BeginHorizontal(); { if (!ModeService.Execute("gui_playbar", isOrWillEnterPlaymode)) { DoPlayButtons(isOrWillEnterPlaymode); } } GUILayout.EndHorizontal(); GUILayout.EndArea(); } // Position right aligned controls controls - start from right to left. pos = new Rect(position.width, 0, 0, 0); // Right spacing side ReserveWidthLeft(space, ref pos); ReserveWidthLeft(dropdownWidth, ref pos); DoLayoutDropDown(EditorToolGUI.GetThinArea(pos)); if (ModeService.HasCapability(ModeCapability.Layers, true)) { ReserveWidthLeft(space, ref pos); ReserveWidthLeft(dropdownWidth, ref pos); DoLayersDropDown(EditorToolGUI.GetThinArea(pos)); } ReserveWidthLeft(space, ref pos); ReserveWidthLeft(dropdownWidth, ref pos); if (EditorGUI.DropdownButton(EditorToolGUI.GetThinArea(pos), s_AccountContent, FocusType.Passive, Styles.dropdown)) { ShowUserMenu(EditorToolGUI.GetThinArea(pos)); } ReserveWidthLeft(space, ref pos); ReserveWidthLeft(standardButtonWidth, ref pos); if (GUI.Button(EditorToolGUI.GetThinArea(pos), s_CloudIcon, Styles.command)) { UnityConnectServiceCollection.instance.ShowService(HubAccess.kServiceName, true, "cloud_icon"); // Should show hub when it's done } foreach (SubToolbar subToolbar in s_SubToolbars) { ReserveWidthLeft(space, ref pos); ReserveWidthLeft(subToolbar.Width, ref pos); subToolbar.OnGUI(EditorToolGUI.GetThinArea(pos)); } if (ModeService.modeCount > 1 && Unsupported.IsDeveloperBuild()) { EditorGUI.BeginChangeCheck(); ReserveWidthLeft(space, ref pos); ReserveWidthLeft(dropdownWidth, ref pos); var selectedModeIndex = EditorGUI.Popup(EditorToolGUI.GetThinArea(pos), ModeService.currentIndex, ModeService.modeNames, Styles.dropdown); if (EditorGUI.EndChangeCheck()) { EditorApplication.delayCall += () => ModeService.ChangeModeByIndex(selectedModeIndex); GUIUtility.ExitGUI(); } } EditorGUI.ShowRepaints(); Highlighter.ControlHighlightGUI(this); }