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(); } } }
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(); }