Merge with extensions-toggle-new-event

--HG--
branch : develop_5.3
release
Simon Jackson 2016-12-24 12:33:02 +00:00
commit 7703ca739c
1 changed files with 24 additions and 0 deletions

View File

@ -12,6 +12,12 @@ namespace UnityEngine.UI
[RequireComponent(typeof(RectTransform))]
public class ExtensionsToggle : Selectable, IPointerClickHandler, ISubmitHandler, ICanvasElement
{
/// <summary>
/// Variable to identify this script, can be int, string or whatever
/// </summary>
//public int UniqueID;
//public string UniqueID;
public enum ToggleTransition
{
None,
@ -22,6 +28,10 @@ namespace UnityEngine.UI
public class ToggleEvent : UnityEvent<bool>
{ }
[Serializable]
public class ToggleEventObject : UnityEvent<ExtensionsToggle>
{ }
/// <summary>
/// Transition type.
/// </summary>
@ -57,6 +67,12 @@ namespace UnityEngine.UI
/// </summary>
public ToggleEvent onValueChanged = new ToggleEvent();
/// <summary>
/// Allow for delegate-based subscriptions for faster events than 'eventReceiver', and allowing for multiple receivers.
/// </summary>
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);
}
}
/// <summary>