-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathUISlider.cs
196 lines (182 loc) · 4.72 KB
/
UISlider.cs
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
using System;
using UnityEngine;
[AddComponentMenu("NGUI/Interaction/NGUI Slider")]
[ExecuteInEditMode]
public class UISlider : UIProgressBar
{
private enum Direction
{
Horizontal,
Vertical,
Upgraded
}
[HideInInspector]
[SerializeField]
private Transform foreground;
[HideInInspector]
[SerializeField]
private float rawValue = 1f;
[HideInInspector]
[SerializeField]
private Direction direction = Direction.Upgraded;
[HideInInspector]
[SerializeField]
protected bool mInverted;
[Obsolete("Use 'value' instead")]
public float sliderValue
{
get
{
return base.value;
}
set
{
base.value = value;
}
}
[Obsolete("Use 'fillDirection' instead")]
public bool inverted
{
get
{
return base.isInverted;
}
set
{
}
}
protected override void Upgrade()
{
if (direction != Direction.Upgraded)
{
mValue = rawValue;
if (foreground != null)
{
mFG = foreground.GetComponent<UIWidget>();
}
if (direction == Direction.Horizontal)
{
mFill = (mInverted ? FillDirection.RightToLeft : FillDirection.LeftToRight);
}
else
{
mFill = ((!mInverted) ? FillDirection.BottomToTop : FillDirection.TopToBottom);
}
direction = Direction.Upgraded;
}
}
protected override void OnStart()
{
GameObject go = (!(mBG != null) || (!(mBG.GetComponent<Collider>() != null) && !(mBG.GetComponent<Collider2D>() != null))) ? base.gameObject : mBG.gameObject;
UIEventListener uIEventListener = UIEventListener.Get(go);
UIEventListener uIEventListener2 = uIEventListener;
uIEventListener2.onPress = (UIEventListener.BoolDelegate)Delegate.Combine(uIEventListener2.onPress, new UIEventListener.BoolDelegate(OnPressBackground));
UIEventListener uIEventListener3 = uIEventListener;
uIEventListener3.onDrag = (UIEventListener.VectorDelegate)Delegate.Combine(uIEventListener3.onDrag, new UIEventListener.VectorDelegate(OnDragBackground));
if (thumb != null && (thumb.GetComponent<Collider>() != null || thumb.GetComponent<Collider2D>() != null) && (mFG == null || thumb != mFG.cachedTransform))
{
UIEventListener uIEventListener4 = UIEventListener.Get(thumb.gameObject);
UIEventListener uIEventListener5 = uIEventListener4;
uIEventListener5.onPress = (UIEventListener.BoolDelegate)Delegate.Combine(uIEventListener5.onPress, new UIEventListener.BoolDelegate(OnPressForeground));
UIEventListener uIEventListener6 = uIEventListener4;
uIEventListener6.onDrag = (UIEventListener.VectorDelegate)Delegate.Combine(uIEventListener6.onDrag, new UIEventListener.VectorDelegate(OnDragForeground));
}
}
protected void OnPressBackground(GameObject go, bool isPressed)
{
if (UICamera.currentScheme != UICamera.ControlScheme.Controller)
{
mCam = UICamera.currentCamera;
base.value = ScreenToValue(UICamera.lastTouchPosition);
if (!isPressed && onDragFinished != null)
{
onDragFinished();
}
}
}
protected void OnDragBackground(GameObject go, Vector2 delta)
{
if (UICamera.currentScheme != UICamera.ControlScheme.Controller)
{
mCam = UICamera.currentCamera;
base.value = ScreenToValue(UICamera.lastTouchPosition);
}
}
protected void OnPressForeground(GameObject go, bool isPressed)
{
if (UICamera.currentScheme != UICamera.ControlScheme.Controller)
{
mCam = UICamera.currentCamera;
if (isPressed)
{
mOffset = ((!(mFG == null)) ? (base.value - ScreenToValue(UICamera.lastTouchPosition)) : 0f);
}
else if (onDragFinished != null)
{
onDragFinished();
}
}
}
protected void OnDragForeground(GameObject go, Vector2 delta)
{
if (UICamera.currentScheme != UICamera.ControlScheme.Controller)
{
mCam = UICamera.currentCamera;
base.value = mOffset + ScreenToValue(UICamera.lastTouchPosition);
}
}
protected void OnKey(KeyCode key)
{
if (base.enabled)
{
float num = (!((float)numberOfSteps > 1f)) ? 0.125f : (1f / (float)(numberOfSteps - 1));
switch (mFill)
{
case FillDirection.LeftToRight:
switch (key)
{
case KeyCode.LeftArrow:
base.value = mValue - num;
break;
case KeyCode.RightArrow:
base.value = mValue + num;
break;
}
break;
case FillDirection.RightToLeft:
switch (key)
{
case KeyCode.LeftArrow:
base.value = mValue + num;
break;
case KeyCode.RightArrow:
base.value = mValue - num;
break;
}
break;
case FillDirection.BottomToTop:
switch (key)
{
case KeyCode.DownArrow:
base.value = mValue - num;
break;
case KeyCode.UpArrow:
base.value = mValue + num;
break;
}
break;
case FillDirection.TopToBottom:
switch (key)
{
case KeyCode.DownArrow:
base.value = mValue + num;
break;
case KeyCode.UpArrow:
base.value = mValue - num;
break;
}
break;
}
}
}
}