Class Toggle
A Toggle is a clickable element that represents a boolean value.
Inheritance
Inherited Members
Namespace: UnityEngine.UIElements
Syntax
public class Toggle : BaseBoolField, IEventHandler, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IResolvedStyle, IBindable, INotifyValueChanged<bool>, IMixedValueSupport
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 thebinding-path
property in a UI Document (.uxml file), or
the C# bindingPath
to the variable name.
Constructors
Toggle()
Creates a Toggle with no label.
Declaration
public Toggle()
Toggle(String)
Creates a Toggle with a Label and a default manipulator.
Declaration
public Toggle(string label)
Parameters
Type | Name | Description |
---|---|---|
String | label | The Label text. |
Remarks
The default manipulator makes it possible to activate the Toggle with a left mouse click.
Fields
checkmarkUssClassName
USS class name of Images in Toggle elements.
Declaration
public static readonly string checkmarkUssClassName
Field Value
Type | Description |
---|---|
String |
Remarks
Unity adds this USS class to the Image sub-element of the Toggle that contains the checkmark image.
inputUssClassName
USS class name of input elements in Toggle elements.
Declaration
public static readonly string inputUssClassName
Field Value
Type | Description |
---|---|
String |
Remarks
Unity adds this USS class to the input sub-element of the Toggle. The input sub-element provides responses to the manipulator.
labelUssClassName
USS class name for Labels in Toggle elements.
Declaration
public static readonly string labelUssClassName
Field Value
Type | Description |
---|---|
String |
Remarks
noTextVariantUssClassName
USS class name of Toggle elements that have no text.
Declaration
public static readonly string noTextVariantUssClassName
Field Value
Type | Description |
---|---|
String |
Remarks
Unity adds this USS class to the Toggle if the Toggle does not have a label.
textUssClassName
USS class name of Text elements in Toggle elements.
Declaration
public static readonly string textUssClassName
Field Value
Type | Description |
---|---|
String |
Remarks
Unity adds this USS class to Text sub-elements of the Toggle.
ussClassName
USS class name for Toggle elements.
Declaration
public static readonly string ussClassName
Field Value
Type | Description |
---|---|
String |
Remarks
Unity adds this USS class to every instance of the Toggle element. Any styling applied to this class affects every Toggle located beside, or below the stylesheet in the visual tree.
Methods
InitLabel()
Declaration
protected override void InitLabel()