Class ToggleGroup
Inherited Members
Namespace: UnityEngine.UI
Assembly: UnityEngine.UI.dll
Syntax
[AddComponentMenu("UI/Toggle Group", 31)]
[DisallowMultipleComponent]
public class ToggleGroup : UIBehaviour
Constructors
ToggleGroup()
Declaration
protected ToggleGroup()
Fields
m_Toggles
Declaration
protected List<Toggle> m_Toggles
Field Value
Type | Description |
---|---|
List<Toggle> |
Properties
allowSwitchOff
Is it allowed that no toggle is switched on?
Declaration
public bool allowSwitchOff { get; set; }
Property Value
Type | Description |
---|---|
bool |
Remarks
If this setting is enabled, pressing the toggle that is currently switched on will switch it off, so that no toggle is switched on. If this setting is disabled, pressing the toggle that is currently switched on will not change its state. Note that even if allowSwitchOff is false, the Toggle Group will not enforce its constraint right away if no toggles in the group are switched on when the scene is loaded or when the group is instantiated. It will only prevent the user from switching a toggle off.
Methods
ActiveToggles()
Returns the toggles in this group that are active.
Declaration
public IEnumerable<Toggle> ActiveToggles()
Returns
Type | Description |
---|---|
IEnumerable<Toggle> | The active toggles in the group. |
Remarks
Toggles belonging to this group but are not active either because their GameObject is inactive or because the Toggle component is disabled, are not returned as part of the list.
AnyTogglesOn()
Are any of the toggles on?
Declaration
public bool AnyTogglesOn()
Returns
Type | Description |
---|---|
bool | Are and of the toggles on? |
EnsureValidState()
Ensure that the toggle group still has a valid state. This is only relevant when a ToggleGroup is Started or a Toggle has been deleted from the group.
Declaration
public void EnsureValidState()
GetFirstActiveToggle()
Returns the toggle that is the first in the list of active toggles.
Declaration
public Toggle GetFirstActiveToggle()
Returns
Type | Description |
---|---|
Toggle | The first active toggle from m_Toggles |
Remarks
Get the active toggle for this group. As the group
NotifyToggleOn(Toggle, bool)
Notify the group that the given toggle is enabled.
Declaration
public void NotifyToggleOn(Toggle toggle, bool sendCallback = true)
Parameters
Type | Name | Description |
---|---|---|
Toggle | toggle | The toggle that got triggered on. |
bool | sendCallback | If other toggles should send onValueChanged. |
OnEnable()
Declaration
protected override void OnEnable()
Overrides
RegisterToggle(Toggle)
Register a toggle with the toggle group so it is watched for changes and notified if another toggle in the group changes.
Declaration
public void RegisterToggle(Toggle toggle)
Parameters
Type | Name | Description |
---|---|---|
Toggle | toggle | The toggle to register with the group. |
SetAllTogglesOff(bool)
Switch all toggles off.
Declaration
public void SetAllTogglesOff(bool sendCallback = true)
Parameters
Type | Name | Description |
---|---|---|
bool | sendCallback |
Remarks
This method can be used to switch all toggles off, regardless of whether the allowSwitchOff property is enabled or not.
Start()
Because all the Toggles have registered themselves in the OnEnabled, Start should check to make sure at least one Toggle is active in groups that do not AllowSwitchOff
Declaration
protected override void Start()
Overrides
UnregisterToggle(Toggle)
Unregister a toggle from the group.
Declaration
public void UnregisterToggle(Toggle toggle)
Parameters
Type | Name | Description |
---|---|---|
Toggle | toggle | The toggle to remove. |