Merged PR for ExtensionsToggle
Updated for UI EXtensions Standards --HG-- branch : develop_5.3pull/413/head
parent
7703ca739c
commit
3e0d105646
|
@ -13,10 +13,9 @@ namespace UnityEngine.UI
|
||||||
public class ExtensionsToggle : Selectable, IPointerClickHandler, ISubmitHandler, ICanvasElement
|
public class ExtensionsToggle : Selectable, IPointerClickHandler, ISubmitHandler, ICanvasElement
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
//public int UniqueID;
|
public string UniqueID;
|
||||||
//public string UniqueID;
|
|
||||||
|
|
||||||
public enum ToggleTransition
|
public enum ToggleTransition
|
||||||
{
|
{
|
||||||
|
@ -46,7 +45,7 @@ namespace UnityEngine.UI
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private ExtensionsToggleGroup m_Group;
|
private ExtensionsToggleGroup m_Group;
|
||||||
|
|
||||||
public ExtensionsToggleGroup group
|
public ExtensionsToggleGroup Group
|
||||||
{
|
{
|
||||||
get { return m_Group; }
|
get { return m_Group; }
|
||||||
set
|
set
|
||||||
|
@ -65,13 +64,15 @@ namespace UnityEngine.UI
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allow for delegate-based subscriptions for faster events than 'eventReceiver', and allowing for multiple receivers.
|
/// Allow for delegate-based subscriptions for faster events than 'eventReceiver', and allowing for multiple receivers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Tooltip("Use this event if you only need the bool state of the toggle that was changed")]
|
||||||
public ToggleEvent onValueChanged = new ToggleEvent();
|
public ToggleEvent onValueChanged = new ToggleEvent();
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allow for delegate-based subscriptions for faster events than 'eventReceiver', and allowing for multiple receivers.
|
/// Allow for delegate-based subscriptions for faster events than 'eventReceiver', and allowing for multiple receivers.
|
||||||
/// </summary>
|
/// </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
|
// Whether the toggle is on
|
||||||
[FormerlySerializedAs("m_IsActive")]
|
[FormerlySerializedAs("m_IsActive")]
|
||||||
|
@ -102,8 +103,7 @@ namespace UnityEngine.UI
|
||||||
if (executing == CanvasUpdate.Prelayout)
|
if (executing == CanvasUpdate.Prelayout)
|
||||||
{
|
{
|
||||||
onValueChanged.Invoke(m_IsOn);
|
onValueChanged.Invoke(m_IsOn);
|
||||||
if(m_IsOn)
|
onToggleChanged.Invoke(this);
|
||||||
onValueChangedOn.Invoke(this);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -164,14 +164,14 @@ namespace UnityEngine.UI
|
||||||
|
|
||||||
// If we are in a new group, and this toggle is on, notify group.
|
// 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.
|
// 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);
|
m_Group.NotifyToggleOn(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether the toggle is currently active.
|
/// Whether the toggle is currently active.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool isOn
|
public bool IsOn
|
||||||
{
|
{
|
||||||
get { return m_IsOn; }
|
get { return m_IsOn; }
|
||||||
set
|
set
|
||||||
|
@ -209,8 +209,7 @@ namespace UnityEngine.UI
|
||||||
if (sendCallback)
|
if (sendCallback)
|
||||||
{
|
{
|
||||||
onValueChanged.Invoke(m_IsOn);
|
onValueChanged.Invoke(m_IsOn);
|
||||||
if(m_IsOn)
|
onToggleChanged.Invoke(this);
|
||||||
onValueChangedOn.Invoke(this);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,7 +242,7 @@ namespace UnityEngine.UI
|
||||||
if (!IsActive() || !IsInteractable())
|
if (!IsActive() || !IsInteractable())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
isOn = !isOn;
|
IsOn = !IsOn;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -48,7 +48,7 @@ namespace UnityEngine.UI
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Toggles[i].isOn = false;
|
m_Toggles[i].IsOn = false;
|
||||||
}
|
}
|
||||||
onToggleGroupChanged.Invoke(AnyTogglesOn());
|
onToggleGroupChanged.Invoke(AnyTogglesOn());
|
||||||
}
|
}
|
||||||
|
@ -78,12 +78,12 @@ namespace UnityEngine.UI
|
||||||
|
|
||||||
public bool AnyTogglesOn()
|
public bool AnyTogglesOn()
|
||||||
{
|
{
|
||||||
return m_Toggles.Find(x => x.isOn) != null;
|
return m_Toggles.Find(x => x.IsOn) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<ExtensionsToggle> ActiveToggles()
|
public IEnumerable<ExtensionsToggle> ActiveToggles()
|
||||||
{
|
{
|
||||||
return m_Toggles.Where(x => x.isOn);
|
return m_Toggles.Where(x => x.IsOn);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetAllTogglesOff()
|
public void SetAllTogglesOff()
|
||||||
|
@ -92,7 +92,7 @@ namespace UnityEngine.UI
|
||||||
m_AllowSwitchOff = true;
|
m_AllowSwitchOff = true;
|
||||||
|
|
||||||
for (var i = 0; i < m_Toggles.Count; i++)
|
for (var i = 0; i < m_Toggles.Count; i++)
|
||||||
m_Toggles[i].isOn = false;
|
m_Toggles[i].IsOn = false;
|
||||||
|
|
||||||
m_AllowSwitchOff = oldAllowSwitchOff;
|
m_AllowSwitchOff = oldAllowSwitchOff;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue