11 [AddComponentMenu(
"UI/Extensions/Extensions Toggle", 31)]
12 [RequireComponent(typeof(RectTransform))]
13 public class ExtensionsToggle : Selectable, IPointerClickHandler, ISubmitHandler, ICanvasElement
50 get {
return m_Group; }
55 if (Application.isPlaying)
58 SetToggleGroup(m_Group,
true);
67 [Tooltip(
"Use this event if you only need the bool state of the toggle that was changed")]
74 [Tooltip(
"Use this event if you need access to the toggle that was changed")]
78 [FormerlySerializedAs(
"m_IsActive")]
79 [Tooltip(
"Is the toggle currently on or off?")]
87 protected override void OnValidate()
92#if UNITY_2018_3_OR_NEWER
93 if (!Application.isPlaying)
95 var prefabType =
UnityEditor.PrefabUtility.GetPrefabType(
this);
96 if (prefabType !=
UnityEditor.PrefabType.Prefab && !Application.isPlaying)
99 CanvasUpdateRegistry.RegisterCanvasElementForLayoutRebuild(
this);
105 public virtual void Rebuild(CanvasUpdate executing)
108 if (executing == CanvasUpdate.Prelayout)
125 SetToggleGroup(m_Group,
false);
131 SetToggleGroup(
null,
false);
141 bool oldValue = !Mathf.Approximately(
graphic.canvasRenderer.GetColor().a, 0);
142 if (m_IsOn != oldValue)
149 base.OnDidApplyAnimationProperties();
167 if (m_Group !=
null && IsActive())
172 if (newGroup !=
null && newGroup != oldGroup &&
IsOn && IsActive())
181 get {
return m_IsOn; }
193 void Set(
bool value,
bool sendCallback)
200 if (m_Group !=
null && IsActive())
224 private void PlayEffect(
bool instant)
230 if (!Application.isPlaying)
231 graphic.canvasRenderer.SetAlpha(m_IsOn ? 1f : 0f);
234 graphic.CrossFadeAlpha(m_IsOn ? 1f : 0f, instant ? 0f : 0.1f,
true);
245 private void InternalToggle()
247 if (!IsActive() || !IsInteractable())
258 if (eventData.button != PointerEventData.InputButton.Left)
264 public virtual void OnSubmit(BaseEventData eventData)
void NotifyToggleOn(ExtensionsToggle toggle)
void UnregisterToggle(ExtensionsToggle toggle)
void RegisterToggle(ExtensionsToggle toggle)
Simple toggle – something that has an 'on' and 'off' states: checkbox, toggle button,...
bool IsOn
Whether the toggle is currently active.
override void OnDidApplyAnimationProperties()
virtual void OnSubmit(BaseEventData eventData)
string UniqueID
Variable to identify this script, change the datatype if needed to fit your use case
override void Start()
Assume the correct visual state.
Graphic graphic
Graphic the toggle should be working with.
virtual void GraphicUpdateComplete()
override void OnDisable()
virtual void Rebuild(CanvasUpdate executing)
virtual void OnPointerClick(PointerEventData eventData)
React to clicks.
ToggleTransition toggleTransition
Transition type.
ToggleEventObject onToggleChanged
Allow for delegate-based subscriptions for faster events than 'eventReceiver', and allowing for multi...
ExtensionsToggleGroup Group
ToggleEvent onValueChanged
Allow for delegate-based subscriptions for faster events than 'eventReceiver', and allowing for multi...
virtual void LayoutComplete()