Base class for toolbar elements intended to be drawn in an Overlay.
Use this class with ICreateHorizontalToolbar and ICreateVerticalToolbar to build Overlays that are dockable in toolbars.
using System.Collections.Generic; using UnityEditor; using UnityEditor.Overlays; using UnityEditor.Toolbars; using UnityEngine; using UnityEngine.UIElements; [Overlay(typeof(SceneView), "My Toolbar Overlay")] class MyOverlay : Overlay, ICreateToolbar { static readonly string[] k_ToolbarItems = new[] { "MyToolbarItem", "SomeOtherToolbarItem" }; public override VisualElement CreatePanelContent() { return new Label("I'm the content shown in panel mode!"); } public IEnumerable<string> toolbarElements => k_ToolbarItems; } [EditorToolbarElement("SomeOtherToolbarItem", typeof(SceneView))] class SomeOtherToolbarItem : EditorToolbarToggle { public SomeOtherToolbarItem() { icon = EditorGUIUtility.FindTexture("CustomTool"); } } // Example toolbar element with multiple controls [EditorToolbarElement("MyToolbarItem", typeof(SceneView))] class MyToolbarItem : OverlayToolbar { public MyToolbarItem() { var icon = AssetDatabase.LoadAssetAtPath<Texture2D>("MyIcon"); Add(new EditorToolbarButton(icon, () => { Debug.Log("Hello!"); })); Add(new EditorToolbarButton(icon, () => { Debug.Log("Hello again!"); })); SetupChildrenAsButtonStrip(); } }
| OverlayToolbar | Create a new OverlayToolbar. |
| SetupChildrenAsButtonStrip | Use this method to apply button strip styling to the contents of this VisualElement. |
| disabledUssClassName | USS class name of local disabled elements. |
| canGrabFocus | Return true if the element can be focused. |
| delegatesFocus | Whether the element should delegate the focus to its children. |
| focusable | True if the element can be focused. |
| focusController | Return the focus controller for this element. |
| tabIndex | An integer used to sort focusables in the focus ring. Must be greater than or equal to zero. |
| childCount | Number of child elements in this object's contentContainer. |
| contentContainer | Child elements are added to it, usually this is the same as the element itself. |
| contentRect | The rectangle of the content area of the element, in the local space of the element. |
| customStyle | Returns the custom style properties accessor for this element. |
| enabledInHierarchy | Returns true if the VisualElement is enabled in its own hierarchy. |
| enabledSelf | Returns true if the VisualElement is enabled locally. |
| experimental | Returns the UIElements experimental interfaces. |
| generateVisualContent | Called when the VisualElement visual contents need to be (re)generated. |