void RefreshActiveContext() { var isGOToolContext = ToolManager.activeContextType == typeof(GameObjectToolContext); if (value && isGOToolContext) { value = false; } else if (!value && !isGOToolContext) { value = true; } //Enable button only if at least one other context beside GameObjectToolContext is available SetEnabled(availableContextCount > 1); //Enable toggle only if at least 2 other contexts are available in addition to GameObjectToolContext ShowDropDown(availableContextCount > 2); var activeContextType = typeof(GameObjectToolContext); if (availableContextCount > 1) { activeContextType = isGOToolContext ? ToolManager.GetLastContextType() : ToolManager.activeContextType; } var content = EditorToolUtility.GetIcon(activeContextType, true); icon = content.image as Texture2D; var activeContextName = EditorToolUtility.GetToolName(ToolManager.activeContextType) + (isGOToolContext ? " (Default)" : ""); tooltip = $"{k_Tooltip}\n\nActive Context: {activeContextName}"; }
void OnEnable() { s_Get = this; pivotMode = (PivotMode)EditorPrefs.GetInt("PivotMode", 0); rectBlueprintMode = EditorPrefs.GetBool("RectBlueprintMode", false); pivotRotation = (PivotRotation)EditorPrefs.GetInt("PivotRotation", 0); var layerSettings = s_LayersStateCache.GetState(m_LayerSettingsKey, new LayerSettings(-1, 0)); visibleLayers = layerSettings.visibleLayersValue; lockedLayers = layerSettings.lockedLayersValue; Selection.selectionChanged += OnSelectionChange; Undo.undoRedoPerformed += OnSelectionChange; EditorToolManager.activeToolChanged += (previous, active) => { #pragma warning disable 618 if (onToolChanged != null) { onToolChanged( EditorToolUtility.GetEnumWithEditorTool(previous), EditorToolUtility.GetEnumWithEditorTool(active)); } #pragma warning restore 618 }; }
static GenericMenu BuildCustomGlobalToolsContextMenu() { var toolHistoryMenu = new GenericMenu() { allowDuplicateNames = true }; bool foundGlobalTools = false; var global = EditorToolUtility.GetCustomEditorToolsForType(null); foreach (var tool in global) { if (tool.targetContext != null && tool.targetContext != ToolManager.activeContextType) { continue; } foundGlobalTools = true; toolHistoryMenu.AddItem( new GUIContent(EditorToolUtility.GetToolMenuPath(tool.editor)), false, () => { ToolManager.SetActiveTool(tool.editor); }); } if (!foundGlobalTools) { toolHistoryMenu.AddDisabledItem(Styles.noToolsAvailable); } return(toolHistoryMenu); }
static void CheckForSelectModeAfterToolQuit() { var toolType = EditorToolUtility.GetEnumWithEditorTool(EditorToolManager.activeTool); if (toolType != Tool.Custom && toolType != Tool.None) { ProBuilderEditor.ResetToLastSelectMode(); } }
static void ToolChanging() { var previousToolType = EditorToolUtility.GetEnumWithEditorTool(EditorToolContext.activeTool); if (previousToolType == Tool.None && ownerID != k_OwnerIdNone) { ChangeEditModeFromToolContext(null, SceneViewEditMode.None); } }
void UpdateState() { SetValueWithoutNotify(IsActiveTool()); var missing = EditorToolUtility.GetEditorToolWithEnum(m_TargetTool) is NoneTool; var display = missing ? DisplayStyle.None : DisplayStyle.Flex; if (style.display != display) { style.display = display; displayChanged?.Invoke(); } }
void UpdateActiveToolIcon() { if (Tools.viewToolActive) { UpdateViewToolIcon(); } else { collapsedIcon = EditorToolUtility.IsManipulationTool(Tools.current) ? EditorToolUtility.GetToolbarIcon(EditorToolManager.activeTool)?.image as Texture2D : null; } }
public ComponentToolButton(T tool) { m_Tool = tool; GUIContent content = EditorToolUtility.GetToolbarIcon(m_Tool); tooltip = content.tooltip; icon = content.image as Texture2D; name = m_Tool == null ? "null" : m_Tool.GetType().Name; this.RegisterValueChangedCallback(evt => { SetToolActive(evt.newValue); }); RegisterCallback <AttachToPanelEvent>(OnAttachedToPanel); RegisterCallback <DetachFromPanelEvent>(OnDetachFromPanel); UpdateState(); }
void UpdateContents() { var tool = EditorToolManager.activeTool; if (EditorToolUtility.IsGlobalTool(tool)) { m_LastGlobalTool = tool; } var content = EditorToolUtility.GetToolbarIcon(m_LastGlobalTool); icon = content.image as Texture2D; tooltip = content.tooltip; style.display = EditorToolUtility.GetNonBuiltinToolCount() > 0 ? DisplayStyle.Flex : DisplayStyle.None; UpdateState(); }
void ShowContextMenu() { var menu = new GenericMenu(); foreach (var ctx in EditorToolUtility.availableGlobalToolContexts) { if (ctx.editor != typeof(GameObjectToolContext)) { menu.AddItem( new GUIContent(EditorToolUtility.GetToolName(ctx.editor)), ToolManager.activeContextType == ctx.editor, () => { if (ToolManager.activeContextType == ctx.editor) { ToolManager.ExitToolContext(); } else { ToolManager.SetActiveContext(ctx.editor); } }); } } foreach (var ctx in EditorToolManager.componentContexts) { menu.AddItem( new GUIContent(EditorToolUtility.GetToolName(ctx.editorType)), EditorToolManager.activeToolContext == ctx.editor, () => { if (EditorToolManager.activeToolContext == ctx.editor) { ToolManager.ExitToolContext(); } else { ToolManager.SetActiveContext(ctx.editorType); } }); } menu.DropDown(worldBound); }
public EditorToolContextButton(T ctx) { m_Context = ctx; GUIContent content = EditorToolUtility.GetToolbarIcon(m_Context); tooltip = content.tooltip; icon = content.image as Texture2D; this.RegisterValueChangedCallback(evt => { EditorToolManager.activeToolContext = evt.newValue ? m_Context : null; }); RegisterCallback <AttachToPanelEvent>(OnAttachedToPanel); RegisterCallback <DetachFromPanelEvent>(OnDetachFromPanel); UpdateState(); }
private void OnEnable() { s_Get = this; pivotMode = (PivotMode)EditorPrefs.GetInt("PivotMode", 0); rectBlueprintMode = EditorPrefs.GetBool("RectBlueprintMode", false); pivotRotation = (PivotRotation)EditorPrefs.GetInt("PivotRotation", 0); visibleLayers = EditorPrefs.GetInt("VisibleLayers", -1); lockedLayers = EditorPrefs.GetInt("LockedLayers", 0); EditorToolContext.activeToolChanged += (previous, active) => { #pragma warning disable 618 if (onToolChanged != null) { onToolChanged( EditorToolUtility.GetEnumWithEditorTool(previous), EditorToolUtility.GetEnumWithEditorTool(active)); } #pragma warning restore 618 }; }
internal static bool EditorToolbar <T>(GUIContent content, T selected, IList <T> tools, out T clicked) where T : IEditor { using (new PrefixScope(content)) { int toolsLength = tools.Count; int index = -1; var buttons = s_ButtonArrays.Get(toolsLength); var enabled = s_BoolArrays.Get(toolsLength); clicked = selected; for (int i = 0; i < toolsLength; i++) { // can happen if the user deletes a tool through scripting if (tools[i] == null) { buttons[i] = GUIContent.none; continue; } if (ReferenceEquals(tools[i], selected)) { index = i; } enabled[i] = tools[i] is EditorTool tool && !tool.IsAvailable() ? false : true; buttons[i] = EditorToolUtility.GetToolbarIcon(tools[i]); } EditorGUI.BeginChangeCheck(); index = GUILayout.Toolbar(index, buttons, enabled, Styles.command); if (EditorGUI.EndChangeCheck()) { clicked = tools[index]; return(true); } return(false); } }
internal static void DoToolContextMenu() { var toolHistoryMenu = new GenericMenu() { allowDuplicateNames = true }; var foundTool = false; // Recent history if (EditorToolContext.GetLastCustomTool() != null) { foundTool = true; toolHistoryMenu.AddDisabledItem(Styles.recentTools); EditorToolContext.GetToolHistory(s_ToolList, true); for (var i = 0; i < Math.Min(k_MaxToolHistory, s_ToolList.Count); i++) { var tool = s_ToolList[i]; if (EditorToolUtility.IsCustomEditorTool(tool.GetType())) { continue; } var name = EditorToolUtility.GetToolName(tool.GetType()); if (tool.IsAvailable()) { toolHistoryMenu.AddItem(new GUIContent(name), false, () => { EditorToolContext.activeTool = tool; }); } else { toolHistoryMenu.AddDisabledItem(new GUIContent(name)); } } toolHistoryMenu.AddSeparator(""); } EditorToolContext.GetCustomEditorTools(s_ToolList, false); // Current selection if (s_ToolList.Any()) { foundTool = true; toolHistoryMenu.AddDisabledItem(Styles.selectionTools); for (var i = 0; i < s_ToolList.Count; i++) { var tool = s_ToolList[i]; if (!EditorToolUtility.IsCustomEditorTool(tool.GetType())) { continue; } var path = new GUIContent(EditorToolUtility.GetToolMenuPath(tool)); if (tool.IsAvailable()) { toolHistoryMenu.AddItem(path, false, () => { EditorToolContext.activeTool = tool; }); } else { toolHistoryMenu.AddDisabledItem(path); } } toolHistoryMenu.AddSeparator(""); } var global = EditorToolUtility.GetCustomEditorToolsForType(null); if (global.Any()) { foundTool = true; toolHistoryMenu.AddDisabledItem(Styles.availableTools); foreach (var toolType in global) { toolHistoryMenu.AddItem( new GUIContent(EditorToolUtility.GetToolMenuPath(toolType)), false, () => { EditorTools.EditorTools.SetActiveTool(toolType); }); } } if (!foundTool) { toolHistoryMenu.AddDisabledItem(Styles.noToolsAvailable); } toolHistoryMenu.ShowAsContext(); }
void UpdateState() { SetValueWithoutNotify(EditorToolUtility.IsGlobalTool(EditorToolManager.activeTool)); }