Merged PR for ExtensionsToggle

Updated for UI EXtensions Standards

--HG--
branch : develop_5.3
pull/413/head
Simon Jackson 2016-12-24 12:41:30 +00:00
parent 7703ca739c
commit 3e0d105646
2 changed files with 15 additions and 16 deletions

View File

@ -13,10 +13,9 @@ namespace UnityEngine.UI
public class ExtensionsToggle : Selectable, IPointerClickHandler, ISubmitHandler, ICanvasElement
{
/// <summary>
/// Variable to identify this script, can be int, string or whatever
/// Variable to identify this script, change the datatype if needed to fit your use case
/// </summary>
//public int UniqueID;
//public string UniqueID;
public string UniqueID;
public enum ToggleTransition
{
@ -46,7 +45,7 @@ namespace UnityEngine.UI
[SerializeField]
private ExtensionsToggleGroup m_Group;
public ExtensionsToggleGroup group
public ExtensionsToggleGroup Group
{
get { return m_Group; }
set
@ -65,13 +64,15 @@ namespace UnityEngine.UI
/// <summary>
/// Allow for delegate-based subscriptions for faster events than 'eventReceiver', and allowing for multiple receivers.
/// </summary>
[Tooltip("Use this event if you only need the bool state of the toggle that was changed")]
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();
[Tooltip("Use this event if you need access to the toggle that was changed")]
public ToggleEventObject onToggleChanged = new ToggleEventObject();
// Whether the toggle is on
[FormerlySerializedAs("m_IsActive")]
@ -102,8 +103,7 @@ namespace UnityEngine.UI
if (executing == CanvasUpdate.Prelayout)
{
onValueChanged.Invoke(m_IsOn);
if(m_IsOn)
onValueChangedOn.Invoke(this);
onToggleChanged.Invoke(this);
}
#endif
}
@ -164,14 +164,14 @@ namespace UnityEngine.UI
// If we are in a new group, and this toggle is on, notify group.
// Note: Don't refer to m_Group here as it's not guaranteed to have been set.
if (newGroup != null && newGroup != oldGroup && isOn && IsActive())
if (newGroup != null && newGroup != oldGroup && IsOn && IsActive())
m_Group.NotifyToggleOn(this);
}
/// <summary>
/// Whether the toggle is currently active.
/// </summary>
public bool isOn
public bool IsOn
{
get { return m_IsOn; }
set
@ -209,8 +209,7 @@ namespace UnityEngine.UI
if (sendCallback)
{
onValueChanged.Invoke(m_IsOn);
if(m_IsOn)
onValueChangedOn.Invoke(this);
onToggleChanged.Invoke(this);
}
}
@ -243,7 +242,7 @@ namespace UnityEngine.UI
if (!IsActive() || !IsInteractable())
return;
isOn = !isOn;
IsOn = !IsOn;
}
/// <summary>

View File

@ -48,7 +48,7 @@ namespace UnityEngine.UI
continue;
}
m_Toggles[i].isOn = false;
m_Toggles[i].IsOn = false;
}
onToggleGroupChanged.Invoke(AnyTogglesOn());
}
@ -78,12 +78,12 @@ namespace UnityEngine.UI
public bool AnyTogglesOn()
{
return m_Toggles.Find(x => x.isOn) != null;
return m_Toggles.Find(x => x.IsOn) != null;
}
public IEnumerable<ExtensionsToggle> ActiveToggles()
{
return m_Toggles.Where(x => x.isOn);
return m_Toggles.Where(x => x.IsOn);
}
public void SetAllTogglesOff()
@ -92,7 +92,7 @@ namespace UnityEngine.UI
m_AllowSwitchOff = true;
for (var i = 0; i < m_Toggles.Count; i++)
m_Toggles[i].isOn = false;
m_Toggles[i].IsOn = false;
m_AllowSwitchOff = oldAllowSwitchOff;
}