Describes a main toolbar element that wraps an arbitrary `VisualElement`.
Use this class to add a main toolbar element whose content doesn't match any of the other MainToolbarElement types, such as MainToolbarButton or MainToolbarToggle. To add a custom element to the main toolbar use a static method registered with MainToolbarElementAttribute to return this class.
using UnityEditor; using UnityEditor.Toolbars; using UnityEngine.UIElements; public class MainToolbarCustomElementExample { [MainToolbarElement("Examples/Custom Clock", defaultDockPosition = MainToolbarDockPosition.Middle)] public static MainToolbarElement ClockElement() { return new MainToolbarCustomElement(() => { var label = new Label(); label.schedule.Execute(() => label.text = System.DateTime.Now.ToLongTimeString()).Every(1000); return label; }); } }
| Constructor | Description |
|---|---|
| MainToolbarCustomElement | Specify the `VisualElement` content of a main toolbar custom element. |
| Property | Description |
|---|---|
| content | The MainToolbarContent describes the content of a main toolbar element. For example, text, icon, or tooltip. |
| displayed | Specifies whether the `VisualElement` for this toolbar element should be displayed or not. Set to `True` by default. |
| enabled | Specifies whether a toolbar element should receive input events. Set to `True` by default. |
| populateContextMenu | Add content to the context menu that appears when you right-click this toolbar element. |