From fa6f1dc76045e69e0abb7fcabea376701377e422 Mon Sep 17 00:00:00 2001 From: Vicente Russo Date: Mon, 24 Oct 2016 15:15:30 -0200 Subject: [PATCH] Added new event that triggers only when toggle value is ON and takes the caller as parameter --HG-- branch : extensions-toggle-new-event --- Scripts/Utilities/ExtensionsToggle.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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); + } } ///