docs.unity.cn
    Show / Hide Table of Contents

    Class ToggleGroup

    Inheritance
    Object
    Object
    Component
    Behaviour
    MonoBehaviour
    UIBehaviour
    ToggleGroup
    Inherited Members
    UIBehaviour.Awake()
    UIBehaviour.OnDisable()
    UIBehaviour.OnDestroy()
    UIBehaviour.IsActive()
    UIBehaviour.OnRectTransformDimensionsChange()
    UIBehaviour.OnBeforeTransformParentChanged()
    UIBehaviour.OnTransformParentChanged()
    UIBehaviour.OnDidApplyAnimationProperties()
    UIBehaviour.OnCanvasGroupChanged()
    UIBehaviour.OnCanvasHierarchyChanged()
    UIBehaviour.IsDestroyed()
    MonoBehaviour.IsInvoking()
    MonoBehaviour.CancelInvoke()
    MonoBehaviour.Invoke(String, Single)
    MonoBehaviour.InvokeRepeating(String, Single, Single)
    MonoBehaviour.CancelInvoke(String)
    MonoBehaviour.IsInvoking(String)
    MonoBehaviour.StartCoroutine(String)
    MonoBehaviour.StartCoroutine(String, Object)
    MonoBehaviour.StartCoroutine(IEnumerator)
    MonoBehaviour.StartCoroutine_Auto(IEnumerator)
    MonoBehaviour.StopCoroutine(IEnumerator)
    MonoBehaviour.StopCoroutine(Coroutine)
    MonoBehaviour.StopCoroutine(String)
    MonoBehaviour.StopAllCoroutines()
    MonoBehaviour.print(Object)
    MonoBehaviour.useGUILayout
    MonoBehaviour.runInEditMode
    Behaviour.enabled
    Behaviour.isActiveAndEnabled
    Component.GetComponent(Type)
    Component.GetComponent<T>()
    Component.TryGetComponent(Type, Component)
    Component.TryGetComponent<T>(T)
    Component.GetComponent(String)
    Component.GetComponentInChildren(Type, Boolean)
    Component.GetComponentInChildren(Type)
    Component.GetComponentInChildren<T>(Boolean)
    Component.GetComponentInChildren<T>()
    Component.GetComponentsInChildren(Type, Boolean)
    Component.GetComponentsInChildren(Type)
    Component.GetComponentsInChildren<T>(Boolean)
    Component.GetComponentsInChildren<T>(Boolean, List<T>)
    Component.GetComponentsInChildren<T>()
    Component.GetComponentsInChildren<T>(List<T>)
    Component.GetComponentInParent(Type, Boolean)
    Component.GetComponentInParent(Type)
    UnityEngine.Component.GetComponentInParent<T>(System.Boolean)
    Component.GetComponentInParent<T>()
    Component.GetComponentsInParent(Type, Boolean)
    Component.GetComponentsInParent(Type)
    Component.GetComponentsInParent<T>(Boolean)
    Component.GetComponentsInParent<T>(Boolean, List<T>)
    Component.GetComponentsInParent<T>()
    Component.GetComponents(Type)
    Component.GetComponents(Type, List<Component>)
    Component.GetComponents<T>(List<T>)
    Component.GetComponents<T>()
    Component.CompareTag(String)
    Component.SendMessageUpwards(String, Object, SendMessageOptions)
    Component.SendMessageUpwards(String, Object)
    Component.SendMessageUpwards(String)
    Component.SendMessageUpwards(String, SendMessageOptions)
    Component.SendMessage(String, Object)
    Component.SendMessage(String)
    Component.SendMessage(String, Object, SendMessageOptions)
    Component.SendMessage(String, SendMessageOptions)
    Component.BroadcastMessage(String, Object, SendMessageOptions)
    Component.BroadcastMessage(String, Object)
    Component.BroadcastMessage(String)
    Component.BroadcastMessage(String, SendMessageOptions)
    Component.transform
    Component.gameObject
    Component.tag
    Object.GetInstanceID()
    Object.GetHashCode()
    Object.Equals(Object)
    Object.Instantiate(Object, Vector3, Quaternion)
    Object.Instantiate(Object, Vector3, Quaternion, Transform)
    Object.Instantiate(Object)
    Object.Instantiate(Object, Transform)
    Object.Instantiate(Object, Transform, Boolean)
    Object.Instantiate<T>(T)
    Object.Instantiate<T>(T, Vector3, Quaternion)
    Object.Instantiate<T>(T, Vector3, Quaternion, Transform)
    Object.Instantiate<T>(T, Transform)
    Object.Instantiate<T>(T, Transform, Boolean)
    Object.Destroy(Object, Single)
    Object.Destroy(Object)
    Object.DestroyImmediate(Object, Boolean)
    Object.DestroyImmediate(Object)
    Object.FindObjectsOfType(Type)
    Object.FindObjectsOfType(Type, Boolean)
    Object.FindObjectsByType(Type, FindObjectsSortMode)
    Object.FindObjectsByType(Type, FindObjectsInactive, FindObjectsSortMode)
    Object.DontDestroyOnLoad(Object)
    Object.DestroyObject(Object, Single)
    Object.DestroyObject(Object)
    Object.FindSceneObjectsOfType(Type)
    Object.FindObjectsOfTypeIncludingAssets(Type)
    Object.FindObjectsOfType<T>()
    UnityEngine.Object.FindObjectsByType<T>(UnityEngine.FindObjectsSortMode)
    UnityEngine.Object.FindObjectsOfType<T>(System.Boolean)
    UnityEngine.Object.FindObjectsByType<T>(UnityEngine.FindObjectsInactive, UnityEngine.FindObjectsSortMode)
    Object.FindObjectOfType<T>()
    UnityEngine.Object.FindObjectOfType<T>(System.Boolean)
    UnityEngine.Object.FindFirstObjectByType<T>()
    UnityEngine.Object.FindAnyObjectByType<T>()
    UnityEngine.Object.FindFirstObjectByType<T>(UnityEngine.FindObjectsInactive)
    UnityEngine.Object.FindAnyObjectByType<T>(UnityEngine.FindObjectsInactive)
    Object.FindObjectsOfTypeAll(Type)
    Object.FindObjectOfType(Type)
    Object.FindFirstObjectByType(Type)
    Object.FindAnyObjectByType(Type)
    Object.FindObjectOfType(Type, Boolean)
    Object.FindFirstObjectByType(Type, FindObjectsInactive)
    Object.FindAnyObjectByType(Type, FindObjectsInactive)
    Object.ToString()
    Object.name
    Object.hideFlags
    Namespace: UnityEngine.UI
    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
    Boolean
    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
    Boolean

    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, Boolean)

    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.

    Boolean sendCallback

    If other toggles should send onValueChanged.

    OnEnable()

    Declaration
    protected override void OnEnable()
    Overrides
    UIBehaviour.OnEnable()

    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(Boolean)

    Switch all toggles off.

    Declaration
    public void SetAllTogglesOff(bool sendCallback = true)
    Parameters
    Type Name Description
    Boolean 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
    UIBehaviour.Start()

    UnregisterToggle(Toggle)

    Unregister a toggle from the group.

    Declaration
    public void UnregisterToggle(Toggle toggle)
    Parameters
    Type Name Description
    Toggle toggle

    The toggle to remove.

    Extension Methods

    UIBehaviourExtensions.InvokeOnEnable(UIBehaviour)
    UIBehaviourExtensions.InvokeOnDisable(UIBehaviour)
    UIBehaviourExtensions.InvokeAwake(UIBehaviour)
    UIBehaviourExtensions.InvokeRebuild(UIBehaviour, CanvasUpdate)
    UIBehaviourExtensions.InvokeLateUpdate(UIBehaviour)
    UIBehaviourExtensions.InvokeUpdate(UIBehaviour)
    UIBehaviourExtensions.InvokeOnRectTransformDimensionsChange(UIBehaviour)
    UIBehaviourExtensions.InvokeOnCanvasGroupChanged(UIBehaviour)
    UIBehaviourExtensions.InvokeOnDidApplyAnimationProperties(UIBehaviour)
    ToggleGroupExtension.InvokeValidateToggleIsInGroup(ToggleGroup, Toggle)
    Back to top Copyright © 2023 Unity Technologies — Terms of use
    Generated by DocFX
    on 12 June 2023