An enhanced Toggle component with additional features including multiple event types and toggle group support.
1 Overview
3 Methods
4 Usage
6 See also
The Extensions Toggle is an enhanced version of Unity’s standard Toggle component. It extends the functionality with:
OnValueChanged (bool) and OnToggleChanged (toggle reference) eventsThis component is ideal when you need more control over toggle behavior or require toggle group features beyond Unity’s standard Toggle.
The properties of the Extensions Toggle control are as follows:
| Property | Description |
|---|---|
| Unique ID | A string identifier for this toggle, useful for identifying which toggle was toggled in callbacks. |
| Interactable | Whether this toggle can be interacted with by the user. |
| Toggle Transition | How the toggle transitions between states: None or Fade. |
| Graphic | The graphic element to transition (typically a checkmark or indicator). |
| Group | The ExtensionsToggleGroup this toggle belongs to. Only one toggle in a group can be on at a time (if group allows). |
| Is On | Whether the toggle is currently in the on state. |
| Toggle Transition | The type of transition when toggling: None or Fade. |
| Fade Duration | How long the fade transition takes when Is On changes. |
| On Value Changed (event) | Invoked when the toggle state changes, passes the new bool value. |
| On Toggle Changed (event) | Invoked when the toggle state changes, passes a reference to the toggle itself. |
| Property | Return Type | Description |
|---|---|---|
| IsOn | bool | Get or set whether the toggle is currently on. |
| UniqueID | string | Get or set the unique identifier string. |
| Group | ExtensionsToggleGroup | Get or set the toggle group this toggle belongs to. |
| Method | Arguments | Description |
|---|---|---|
| Set | value (bool) | Set the toggle state without triggering callbacks. |
| Set | value (bool), sendCallback (bool) | Set the toggle state with optional callback triggering. |
| OnPointerClick | PointerEventData | Handles left mouse click to toggle. |
| OnSubmit | BaseEventData | Handles submission (Enter/Space key or gamepad button) to toggle. |
Add the Extensions Toggle component to a GameObject:
“Add Component -> UI -> Extensions -> Extensions Toggle”
public ExtensionsToggle toggle;
void Start()
{
// Listen to toggle state changes
toggle.onValueChanged.AddListener(OnToggleChanged);
}
void OnToggleChanged(bool isOn)
{
Debug.Log("Toggle is " + (isOn ? "ON" : "OFF"));
}
public ExtensionsToggle toggle;
void Start()
{
toggle.UniqueID = "sound_toggle";
toggle.onToggleChanged.AddListener(OnToggleChanged);
}
void OnToggleChanged(ExtensionsToggle toggleThatChanged)
{
if (toggleThatChanged.UniqueID == "sound_toggle")
{
AudioListener.pause = !toggleThatChanged.IsOn;
}
}
public ExtensionsToggle option1, option2, option3;
public ExtensionsToggleGroup optionGroup;
void Start()
{
// Assign toggles to the group
option1.Group = optionGroup;
option2.Group = optionGroup;
option3.Group = optionGroup;
// Only one toggle can be on at a time
optionGroup.onToggleGroupChanged.AddListener(OnOptionSelected);
}
void OnOptionSelected(bool anyToggleOn)
{
if (anyToggleOn)
{
var selected = optionGroup.SelectedToggle;
Debug.Log("Selected option: " + selected.UniqueID);
}
}
public ExtensionsToggle toggle;
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
// Toggle the state
toggle.IsOn = !toggle.IsOn;
}
}
Coming soon…
Unity UI Extensions Contributors