Version: Unity 6.7 Alpha (6000.7)
LanguageEnglish
  • C#

MainToolbarCustomElement

class in UnityEditor.Toolbars

/

Inherits from:Toolbars.MainToolbarElement

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

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;
        });
    }
}

Constructors

Constructor Description
MainToolbarCustomElementSpecify the `VisualElement` content of a main toolbar custom element.

Inherited Members

Properties

PropertyDescription
contentThe MainToolbarContent describes the content of a main toolbar element. For example, text, icon, or tooltip.
displayedSpecifies whether the `VisualElement` for this toolbar element should be displayed or not. Set to `True` by default.
enabledSpecifies whether a toolbar element should receive input events. Set to `True` by default.
populateContextMenuAdd content to the context menu that appears when you right-click this toolbar element.