forked from MattRix/UnityDecompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToggle.cs
More file actions
214 lines (188 loc) · 4.12 KB
/
Toggle.cs
File metadata and controls
214 lines (188 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
using System;
using UnityEditor;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.Serialization;
namespace UnityEngine.UI
{
[AddComponentMenu("UI/Toggle", 31), RequireComponent(typeof(RectTransform))]
public class Toggle : Selectable, IPointerClickHandler, ISubmitHandler, ICanvasElement, IEventSystemHandler
{
public enum ToggleTransition
{
None,
Fade
}
[Serializable]
public class ToggleEvent : UnityEvent<bool>
{
}
public Toggle.ToggleTransition toggleTransition = Toggle.ToggleTransition.Fade;
public Graphic graphic;
[SerializeField]
private ToggleGroup m_Group;
public Toggle.ToggleEvent onValueChanged = new Toggle.ToggleEvent();
[FormerlySerializedAs("m_IsActive"), SerializeField, Tooltip("Is the toggle currently on or off?")]
private bool m_IsOn;
public ToggleGroup group
{
get
{
return this.m_Group;
}
set
{
this.m_Group = value;
if (Application.isPlaying)
{
this.SetToggleGroup(this.m_Group, true);
this.PlayEffect(true);
}
}
}
public bool isOn
{
get
{
return this.m_IsOn;
}
set
{
this.Set(value);
}
}
protected Toggle()
{
}
protected override void OnValidate()
{
base.OnValidate();
PrefabType prefabType = PrefabUtility.GetPrefabType(this);
if (prefabType != PrefabType.Prefab && !Application.isPlaying)
{
CanvasUpdateRegistry.RegisterCanvasElementForLayoutRebuild(this);
}
}
public virtual void Rebuild(CanvasUpdate executing)
{
if (executing == CanvasUpdate.Prelayout)
{
this.onValueChanged.Invoke(this.m_IsOn);
}
}
public virtual void LayoutComplete()
{
}
public virtual void GraphicUpdateComplete()
{
}
protected override void OnEnable()
{
base.OnEnable();
this.SetToggleGroup(this.m_Group, false);
this.PlayEffect(true);
}
protected override void OnDisable()
{
this.SetToggleGroup(null, false);
base.OnDisable();
}
protected override void OnDidApplyAnimationProperties()
{
if (this.graphic != null)
{
bool flag = !Mathf.Approximately(this.graphic.canvasRenderer.GetColor().a, 0f);
if (this.m_IsOn != flag)
{
this.m_IsOn = flag;
this.Set(!flag);
}
}
base.OnDidApplyAnimationProperties();
}
private void SetToggleGroup(ToggleGroup newGroup, bool setMemberValue)
{
ToggleGroup group = this.m_Group;
if (this.m_Group != null)
{
this.m_Group.UnregisterToggle(this);
}
if (setMemberValue)
{
this.m_Group = newGroup;
}
if (newGroup != null && this.IsActive())
{
newGroup.RegisterToggle(this);
}
if (newGroup != null && newGroup != group && this.isOn && this.IsActive())
{
newGroup.NotifyToggleOn(this);
}
}
private void Set(bool value)
{
this.Set(value, true);
}
private void Set(bool value, bool sendCallback)
{
if (this.m_IsOn != value)
{
this.m_IsOn = value;
if (this.m_Group != null && this.IsActive())
{
if (this.m_IsOn || (!this.m_Group.AnyTogglesOn() && !this.m_Group.allowSwitchOff))
{
this.m_IsOn = true;
this.m_Group.NotifyToggleOn(this);
}
}
this.PlayEffect(this.toggleTransition == Toggle.ToggleTransition.None);
if (sendCallback)
{
this.onValueChanged.Invoke(this.m_IsOn);
}
}
}
private void PlayEffect(bool instant)
{
if (!(this.graphic == null))
{
if (!Application.isPlaying)
{
this.graphic.canvasRenderer.SetAlpha((!this.m_IsOn) ? 0f : 1f);
}
else
{
this.graphic.CrossFadeAlpha((!this.m_IsOn) ? 0f : 1f, (!instant) ? 0.1f : 0f, true);
}
}
}
protected override void Start()
{
this.PlayEffect(true);
}
private void InternalToggle()
{
if (this.IsActive() && this.IsInteractable())
{
this.isOn = !this.isOn;
}
}
public virtual void OnPointerClick(PointerEventData eventData)
{
if (eventData.button == PointerEventData.InputButton.Left)
{
this.InternalToggle();
}
}
public virtual void OnSubmit(BaseEventData eventData)
{
this.InternalToggle();
}
Transform ICanvasElement.get_transform()
{
return base.transform;
}
}
}