// ---------------------------------------------------------------------------- // // Photon Voice Demo for PUN- Copyright (C) 2016 Exit Games GmbH // // // Unity UI extension class that should be used with Unity's built-in Toggle // to broadcast value change in a better way. // // developer@photonengine.com // ---------------------------------------------------------------------------- namespace ExitGames.Demos.DemoPunVoice { using UnityEngine; using UnityEngine.UI; [RequireComponent(typeof(Toggle))] [DisallowMultipleComponent] public class BetterToggle : MonoBehaviour { private Toggle toggle; public delegate void OnToggle(Toggle toggle); public static event OnToggle ToggleValueChanged; private void Start() { this.toggle = this.GetComponent(); this.toggle.onValueChanged.AddListener(delegate { this.OnToggleValueChanged(); }); } public void OnToggleValueChanged() { if (ToggleValueChanged != null) { ToggleValueChanged(this.toggle); } } } }