Button
This is a clickable button.
Read time 7 minutesLast updated 2 days ago
Definition
- Type: Class
- Namespace: UnityEngine.UIElements
- Assembly: UnityEngine.UIElementsModule
- Inherits from: TextElement
- Implements: IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IVisualElementScheduler, IBindable, INotifyValueChanged<string>, ITextEdition, ITextElementExperimentalFeatures, IExperimentalFeatures, ITextSelection
public class Button : TextElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IVisualElementScheduler, IBindable, INotifyValueChanged<string>, ITextEdition, ITextElementExperimentalFeatures, IExperimentalFeatures, ITextSelection
Remarks
A Button has a text label element that can respond to pointer and mouse events. You can add an icon to pair it with the text by assigning a Background (Texture, RenderTexture, Sprite or Vector Image) to the iconImage API or icon-image UXML property. Please note that by providing an icon image, this will automatically update the Button's hierarchy to contain an Image and a text label element.
By default, a single left mouse click activates the Button's Clickable property button. To remove this activator, or add more activators, modify the property. For details, see ManipulatorActivationFilter.
clickable.activatorsTo bind a Button's text value to the contents of a variable, set the property in the UXML file, or the property in the C# code, to a string that contains the variable name.
binding-pathbindingPathFor more information, refer to UXML element Button.
Static Fields
Value | Description |
|---|---|
| iconOnlyUssClassName | The USS class name for Button elements with an icon only, no text. |
| iconUssClassName | The USS class name for Button elements with an icon. |
| imageUSSClassName | The USS class name of the image element that will be used to display the icon texture. |
| ussClassName | USS class name of elements of this type. |
Constructors
Constructor | Description |
|---|---|
| Button() | Constructs a Button. |
| Button(System.Action) | Constructs a button with an Action that is triggered when the button is clicked. |
| Button(UnityEngine.UIElements.Background,System.Action) | Constructs a button with a Background and an Action. The image definition will be used to represent an icon while the Action is triggered when the button is clicked. |
Properties
Property | Description |
|---|---|
| clickable | Clickable MouseManipulator for this Button. |
| iconImage | The Texture, Sprite, or VectorImage that will represent an icon within a Button element. |
Events
Member | Description |
|---|---|
| clicked | Callback triggered when the button is clicked. |