ToolbarButton
Editor-only control that serves as a button in a Toolbar.
Read time 10 minutesLast updated 2 days ago
Definition
- Type: Class
- Namespace: UnityEditor.UIElements
- Assembly: UnityEditor.CoreModule
- Inherits from: Button
- Implements: IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IVisualElementScheduler, ICustomStyle, IBindable, INotifyValueChanged<string>, ITextEdition, ITextElementExperimentalFeatures, IExperimentalFeatures, ITextSelection
[UxmlElement][Icon("UIToolkit/Icons/ToolbarButton.png")]public class ToolbarButton : Button, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IVisualElementScheduler, ICustomStyle, IBindable, INotifyValueChanged<string>, ITextEdition, ITextElementExperimentalFeatures, IExperimentalFeatures, ITextSelection
Remarks
For more information, refer to UXML element ToolbarButton.
Additional Resources: Button, Toolbar
The following C# example creates a ToolbarButton with a label and click callback:
Examples
using UnityEngine;using UnityEditor;using UnityEditor.UIElements;public class ToolbarExample : EditorWindow{ [MenuItem("Window/Toolbar Example")] public static void ShowExample() { GetWindow<ToolbarExample>("Toolbar Example"); } void CreateGUI() { // Create a Toolbar var toolbar = new Toolbar(); // Create the first ToolbarButton var button1 = new ToolbarButton(() => { Debug.Log("First button clicked"); }) { text = "Button 1" }; // Create the second ToolbarButton var button2 = new ToolbarButton(() => { Debug.Log("Second button clicked"); }) { text = "Button 2" }; // Add the buttons to the toolbar toolbar.Add(button1); toolbar.Add(button2); // Add the toolbar to the window's rootVisualElement rootVisualElement.Add(toolbar); }}
Static Fields
Value | Description |
|---|---|
| ussClassName | USS class name of elements of this type. |
Constructors
Constructor | Description |
|---|---|
| ToolbarButton() | Constructor. |
| ToolbarButton(System.Action) | Constructor. |