namespace UIWidgets.Examples { using UIWidgets; using UnityEngine; /// /// Test Switch. /// public class SwitchTest : MonoBehaviour { /// /// Switch. /// [SerializeField] protected Switch Switch; /// /// Adds listeners. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Required")] protected virtual void Start() { if (Switch != null) { Switch.OnValueChanged.AddListener(OnSwitchChanged); } } /// /// Handle switch changed event. /// /// Status. protected virtual void OnSwitchChanged(bool status) { Debug.Log(string.Format("switch status: {0}", status.ToString())); } /// /// Remove listeners. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Required")] protected virtual void OnDestroy() { if (Switch != null) { Switch.OnValueChanged.RemoveListener(OnSwitchChanged); } } } }