Пример #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);
            }
        }
Пример #2
0
        public BuiltinToolsStrip()
        {
            name = "BuiltinTools";

            EditorToolbarUtility.SetupChildrenAsButtonStrip(this);

            // Only show the contexts dropdown if there are non-builtin contexts available
            if (EditorToolUtility.toolContextsInProject > 1)
            {
                var contexts = new ToolContextButton();
                contexts.AddToClassList(EditorToolbarUtility.aloneStripElementClassName);
                Add(contexts);
            }

            // View and Builtin Transform Tools
            m_DefaultTools = new VisualElement()
            {
                name = "Builtin View and Transform Tools"
            };
            m_DefaultTools.AddToClassList("toolbar-contents");
            Add(m_DefaultTools);

            this.RegisterCallback <AttachToPanelEvent>(OnAttachToPanel);
            this.RegisterCallback <DetachFromPanelEvent>(OnDetachFromPanel);

            CreateDefaultTools();

            // Custom global tools button (only shown if custom global tools exist in project)
            // A single "overflow" toggle+dropdown for additional global tools
            var customToolButton = new LastCustomToolButton();

            customToolButton.AddToClassList(EditorToolbarUtility.aloneStripElementClassName);
            Add(customToolButton);

            // Component tools are last
            Add(new ComponentToolsStrip());
        }