Ejemplo n.º 1
0
        void Refresh()
        {
            for (int i = childCount - 1; i > -1; i--)
            {
                RemoveAt(i);
            }

            AddToClassList("toolbar-contents");

            if ((EditorToolManager.GetCustomEditorToolsCount(false) + EditorToolManager.availableComponentContextCount) < 1)
            {
                return;
            }

            EditorToolManager.GetComponentToolsForSharedTracker(s_EditorTools);
            s_SortedTools.Clear();

            // Display available tools grouped by their target component
            foreach (var tool in s_EditorTools)
            {
                var component = tool.target;

                if (component == null)
                {
                    continue;
                }

                if (!s_SortedTools.TryGetValue(component, out List <EditorTool> editorTools))
                {
                    editorTools = new List <EditorTool>();
                    s_SortedTools.Add(component, editorTools);
                }
                editorTools.Add(tool);
            }

            foreach (var kvp in s_SortedTools)
            {
                var tools = new VisualElement()
                {
                    name = "Component Tools"
                };
                tools.AddToClassList("toolbar-contents");

                foreach (var tool in kvp.Value)
                {
                    tools.Add(new ComponentToolButton <EditorTool>(tool));
                }
                EditorToolbarUtility.SetupChildrenAsButtonStrip(tools);

                Add(tools);
            }
        }