diff --git a/Scripts/Utilities/ExtensionsToggle.cs b/Scripts/Utilities/ExtensionsToggle.cs index 0097080..5766c1c 100644 --- a/Scripts/Utilities/ExtensionsToggle.cs +++ b/Scripts/Utilities/ExtensionsToggle.cs @@ -12,6 +12,12 @@ namespace UnityEngine.UI [RequireComponent(typeof(RectTransform))] public class ExtensionsToggle : Selectable, IPointerClickHandler, ISubmitHandler, ICanvasElement { + /// + /// Variable to identify this script, can be int, string or whatever + /// + //public int UniqueID; + //public string UniqueID; + public enum ToggleTransition { None, @@ -22,6 +28,10 @@ namespace UnityEngine.UI public class ToggleEvent : UnityEvent { } + [Serializable] + public class ToggleEventObject : UnityEvent + { } + /// /// Transition type. /// @@ -57,6 +67,12 @@ namespace UnityEngine.UI /// public ToggleEvent onValueChanged = new ToggleEvent(); + + /// + /// Allow for delegate-based subscriptions for faster events than 'eventReceiver', and allowing for multiple receivers. + /// + public ToggleEventObject onValueChangedOn = new ToggleEventObject(); + // Whether the toggle is on [FormerlySerializedAs("m_IsActive")] [Tooltip("Is the toggle currently on or off?")] @@ -84,7 +100,11 @@ namespace UnityEngine.UI { #if UNITY_EDITOR if (executing == CanvasUpdate.Prelayout) + { onValueChanged.Invoke(m_IsOn); + if(m_IsOn) + onValueChangedOn.Invoke(this); + } #endif } @@ -187,7 +207,11 @@ namespace UnityEngine.UI // It's up to the user to ignore a selection being set to the same value it already was, if desired. PlayEffect(toggleTransition == ToggleTransition.None); if (sendCallback) + { onValueChanged.Invoke(m_IsOn); + if(m_IsOn) + onValueChangedOn.Invoke(this); + } } ///