Toggle
A Toggle is a clickable element that represents a boolean value.
Read time 10 minutesLast updated 2 days ago
Definition
- Type: Class
- Namespace: UnityEngine.UIElements
- Assembly: UnityEngine.UIElementsModule
- Inherits from: BaseBoolField
- Implements: IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, ICustomStyle, IBindable, IMixedValueSupport, INotifyValueChanged<bool>
[UxmlElement(libraryPath = "Controls")][Icon("UIToolkit/Icons/Toggle.png")]public class Toggle : BaseBoolField, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, ICustomStyle, IBindable, IMixedValueSupport, INotifyValueChanged<bool>
Remarks
A Toggle control consists of a label and an input field. The input field contains a sprite for the control. By default, this is a checkbox (Unity does not provide a separate checkbox control type) in all of its possible states, for example, normal, hovered, checked, and unchecked. You can style a Toggle control to change its appearance to something else, for example, an on/off switch.
When a Toggle is clicked, its state alternates between between true and false. You can also think of these states as on and off, or enabled and disabled.
To bind the Toggle's state to a boolean variable, set the property in a UI Document (.uxml file), or the C# to the variable name.
binding-pathbindingPathFor more information, refer to UXML element Toggle.
Static Fields
Value | Description |
|---|---|
| checkmarkUssClassName | USS class name of Images in Toggle elements. |
| inputUssClassName | USS class name of input elements in Toggle elements. |
| labelUssClassName | USS class name for Labels in Toggle elements. |
| mixedValuesUssClassName | USS class name of Toggle elements that have mixed values |
| textUssClassName | USS class name of Text elements in Toggle elements. |
| ussClassName | USS class name for Toggle elements. |
Constructors
Constructor | Description |
|---|---|
| Toggle() | Creates a Toggle with no label. |
| Toggle(System.String) | Creates a Toggle with a Label and a default manipulator. |