static void DoContextualToolbarOverlay(UnityEngine.Object target, SceneView sceneView) { GUILayout.BeginHorizontal(GUIStyle.none, GUILayout.MinWidth(210), GUILayout.Height(30)); EditorToolContext.GetCustomEditorTools(s_EditorToolModes, false); if (s_EditorToolModes.Count > 0) { EditorGUI.BeginChangeCheck(); EditorGUILayout.EditorToolbar(s_EditorToolModes); if (EditorGUI.EndChangeCheck()) { foreach (var inspector in InspectorWindow.GetInspectors()) { foreach (var editor in inspector.tracker.activeEditors) { editor.Repaint(); } } } } else { var fontStyle = EditorStyles.label.fontStyle; EditorStyles.label.fontStyle = FontStyle.Italic; GUILayout.Label(Styles.noToolsAvailable, EditorStyles.centeredGreyMiniLabel); EditorStyles.label.fontStyle = fontStyle; } GUILayout.EndHorizontal(); }
public static void EditorToolbarForTarget(UObject target) { if (target == null) { throw new ArgumentNullException("target"); } EditorToolContext.GetCustomEditorToolsForTarget(target, s_CustomEditorTools, true); EditorToolbar <EditorTool>(s_CustomEditorTools); }
public static void EditorToolbarForTarget(GUIContent content, UObject target) { if (target == null) { throw new ArgumentNullException("target"); } GUILayout.BeginHorizontal(); PrefixLabel(content); EditorToolContext.GetCustomEditorToolsForTarget(target, s_CustomEditorTools, true); EditorToolbar <EditorTool>(s_CustomEditorTools); GUILayout.EndHorizontal(); }
void DoToolButtons(Rect rect) { const int builtinIconsLength = 6; // Handle temporary override with ALT GUI.changed = false; int displayTool = Tools.viewToolActive ? 0 : (int)Tools.current; for (int i = 1; i < builtinIconsLength; i++) { s_ShownToolIcons[i] = s_ToolIcons[i - 1 + (i == displayTool ? s_ShownToolIcons.Length - 1 : 0)]; s_ShownToolIcons[i].tooltip = s_ToolIcons[i - 1].tooltip; } var lastCustomTool = EditorToolContext.GetLastCustomTool(); if (lastCustomTool != null) { s_ShownToolIcons[builtinIconsLength] = lastCustomTool.toolbarIcon ?? s_CustomToolIcon; } else { s_ShownToolIcons[builtinIconsLength] = s_CustomToolIcon; } s_ShownToolIcons[0] = s_ViewToolIcons[(int)Tools.viewTool + (displayTool == 0 ? s_ViewToolOnOffset : 0)]; displayTool = GUI.Toolbar(rect, displayTool, s_ShownToolIcons, s_ToolControlNames, Styles.command, GUI.ToolbarButtonSize.FitToContents); if (GUI.changed) { var evt = Event.current; if (displayTool == (int)Tool.Custom && ( EditorToolContext.GetLastCustomTool() == null || evt.button == 1 || (evt.button == 0 && evt.modifiers == EventModifiers.Alt)) ) { EditorToolGUI.DoToolContextMenu(); } else { Tools.current = (Tool)displayTool; Tools.ResetGlobalHandleRotation(); } } }
public static void EditorToolbar <T>(IList <T> tools) where T : EditorTool { EditorTool selected; if (EditorToolbar(EditorToolContext.activeTool, tools, out selected)) { if (selected == EditorToolContext.activeTool) { EditorToolContext.RestorePreviousTool(); } else { EditorToolContext.activeTool = selected; } } }
public static void EditorToolbar <T>(IList <T> tools) where T : EditorTool { int toolsLength = tools.Count; int selected = -1; var buttons = s_ButtonArrays.Get(toolsLength); var enabled = s_BoolArrays.Get(toolsLength); 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 (tools[i] == EditorToolContext.activeTool) { selected = i; } enabled[i] = tools[i].IsAvailable(); buttons[i] = tools[i].toolbarIcon ?? GUIContent.none; } int previous = selected; EditorGUI.BeginChangeCheck(); selected = GUILayout.Toolbar(selected, buttons, enabled, "Command"); if (EditorGUI.EndChangeCheck()) { if (selected == previous) { EditorToolContext.RestorePreviousTool(); } else { EditorToolContext.activeTool = tools[selected]; } } }
static EditorTool GetTool(IToolModeOwner owner, SceneViewEditMode mode) { var editor = owner as Editor; if (editor == null) { return(null); } var editorType = editor.GetType(); return(EditorToolContext.GetCustomEditorTool(x => { var tool = x as EditModeTool; return tool != null && tool.editorType == editorType && tool.target == editor.target; }, true)); }
/// <summary> /// Toggles the state of active editor tool with the type passed in. /// </summary> /// <remarks> /// This will change the current active editor tool if the type passed in /// is not the same as the current active editor tool. Otherwise, it will /// set the View Mode tool as the current active editor tool. /// </remarks> /// <param name="type"> /// The type of editor tool. This must be inherited from EditorTool. /// </param> public static void ToggleActiveEditorTool(Type type) { if (EditorTools.EditorTools.activeToolType != type) { SetActiveEditorTool(type); } else { // Switch out of TilemapEditorTool if possible var lastTool = EditorToolContext.GetLastTool(x => !(x is TilemapEditorTool)); if (lastTool != null) { EditorTools.EditorTools.SetActiveTool(lastTool); } else { EditorTools.EditorTools.SetActiveTool(typeof(ViewModeTool)); } } }
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(); }
public static void ResetToolToPrevious() { EditorToolContext.RestorePreviousTool(); }