Skip to content

ThreeStatesToggle

Ilia Petrov-Komotskii edited this page Sep 24, 2026 · 6 revisions

ThreeStatesToggle

Toggle with three states: on, off, and undefined. Click cycles on → off → undefined → on. State is bool? (true / false / null).

using Mane.Unity.UI;
using UnityEngine;

public class FilterRow : MonoBehaviour
{
    [SerializeField] private ThreeStatesToggle _include;

    private void OnEnable() => _include.StateValueChanged += OnChanged;
    private void OnDisable() => _include.StateValueChanged -= OnChanged;

    private void OnChanged(bool? value)
    {
        if (value == null)
            ShowAll();
        else
            Filter(value.Value);
    }
}

Graphics

Unity's Toggle.graphic is the on visual. Assign:

  • offGraphic — shown while off
  • undefinedGraphic — shown while undefined

Alpha is faded (CrossFadeAlpha in play mode; instant in edit mode). Missing graphics are skipped.

Events and isOn

  • onStateValueChanged — UnityEvent<bool?>
  • StateValueChanged — same listeners as a C# event
  • Setting isOn also sets State to true or false (never undefined).
  • Setting State updates isOn (true → on; false and null → off).

ToggleGroup is not supported (group is obsolete and throws).

Animation: if undefinedGraphic alpha is non-zero, state is treated as undefined (OnDidApplyAnimationProperties).

Prefab and inspector

GameObject → UI (Canvas) → Three States Toggle - Mane Tools instantiates the packaged prefab under a Canvas (UICanvasTools.PlaceUIElement) and starts Hierarchy rename.

The custom inspector includes Editor Tools (mode, wrap-around, explicit targets, Visualize).

Screenshot: three-states-toggle.png — same control in on / off / undefined in the scene. Host at https://raw.githubusercontent.com/wiki/ManeFunction/ManeTools-UnityUI/three-states-toggle.png.

Clone this wiki locally