Class UnityUiToggleComponent
Unity UI toggle component that provides toggle and submit functionality for boolean value selection.
Combines toggle behavior with submittable actions to create interactive UI elements for binary choices.
Implements both IUiToggleable and IUiSubmittable interfaces for comprehensive boolean input handling within the Unity UI system.
Inherited Members
Namespace: Serenity.Ui.Infrastructure.Components
Assembly: Serenity.UnityUi.Infrastructure.dll
Syntax
public class UnityUiToggleComponent : UnityUiInteractableComponent, IUiInteractable, IUiComponent, IUiToggleable, IComponent, IFoundationSettings, IUiSubmittable
Constructors
UnityUiToggleComponent()
Initializes a new instance of the UnityUiToggleComponent.
Sets up the component type as a toggle interaction for proper UI behavior and event handling.
Declaration
public UnityUiToggleComponent()
Properties
SubmittableActions
Gets or sets the submittable actions interface for submission event handling.
Manages callbacks for submission events when the toggle is activated or confirmed.
Declaration
public IUiSubmittableActions SubmittableActions { get; set; }
Property Value
| Type | Description |
|---|---|
| IUiSubmittableActions | The submittable actions interface |
ToggleableActions
Gets or sets the toggleable actions interface for toggle event handling.
Manages callbacks for toggle state changes and boolean value interactions.
Declaration
public IUiToggleableActions ToggleableActions { get; set; }
Property Value
| Type | Description |
|---|---|
| IUiToggleableActions | The toggleable actions interface |
ToggleableParameters
Gets or sets the toggleable parameters interface for toggle configuration.
Provides access to the current boolean value and toggle-specific settings.
Declaration
public IUiToggleableParameters ToggleableParameters { get; set; }
Property Value
| Type | Description |
|---|---|
| IUiToggleableParameters | The toggleable parameters interface |
Value
Gets or sets the boolean value of the toggle component.
Provides direct access to the toggle state with automatic parameter synchronization.
Declaration
public bool Value { get; set; }
Property Value
| Type | Description |
|---|---|
| bool | The current boolean value |
Methods
OnEnable()
Unity lifecycle method called when the component is enabled.
Initializes the toggle value from parameters and calls base initialization for proper component setup.
Declaration
public override void OnEnable()
Overrides
SetValue(bool)
Sets the toggle value directly with a boolean.
Updates both the component parameters and the Unity Toggle UI element without triggering change events.
Uses Unity's SetIsOnWithoutNotify method to prevent recursive event triggering.
Declaration
public void SetValue(bool newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | newValue | The boolean value to set for the toggle |
SetValue(string)
Sets the toggle value from a string representation.
Parses the string value as a boolean and applies it to the toggle component with validation.
Supports common boolean string representations for flexible value setting.
Declaration
public override void SetValue(string value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | The string value to parse and set ("true" or "false") |
Overrides
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when the string cannot be parsed as a boolean value |
Submit()
Handles submission actions by toggling the value and triggering submission callbacks.
Combines toggle functionality with submission behavior for comprehensive user interaction handling.
Calls base submit functionality and invokes both toggle and submit action callbacks.
Declaration
public override void Submit()
Overrides
Toggle()
Toggles the current boolean value and triggers toggle action callbacks.
Flips the current state from true to false or vice versa and invokes toggle event handlers.
Provides the core toggle functionality for user interactions.
Declaration
public void Toggle()