예제 #1
0
        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;
                }
            }
        }
예제 #2
0
        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];
                }
            }
        }
예제 #3
0
 public static void ResetToolToPrevious()
 {
     EditorToolContext.RestorePreviousTool();
 }