-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathUIScrollBar.cs
158 lines (148 loc) · 3.8 KB
/
UIScrollBar.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
using System;
using UnityEngine;
[AddComponentMenu("NGUI/Interaction/NGUI Scroll Bar")]
[ExecuteInEditMode]
public class UIScrollBar : UISlider
{
private enum Direction
{
Horizontal,
Vertical,
Upgraded
}
[HideInInspector]
[SerializeField]
protected float mSize = 1f;
[HideInInspector]
[SerializeField]
private float mScroll;
[HideInInspector]
[SerializeField]
private Direction mDir = Direction.Upgraded;
[Obsolete("Use 'value' instead")]
public float scrollValue
{
get
{
return base.value;
}
set
{
base.value = value;
}
}
public float barSize
{
get
{
return mSize;
}
set
{
float num = Mathf.Clamp01(value);
if (mSize != num)
{
mSize = num;
mIsDirty = true;
if (NGUITools.GetActive(this))
{
if (UIProgressBar.current == null && onChange != null)
{
UIProgressBar.current = this;
EventDelegate.Execute(onChange);
UIProgressBar.current = null;
}
ForceUpdate();
}
}
}
}
protected override void Upgrade()
{
if (mDir != Direction.Upgraded)
{
mValue = mScroll;
if (mDir == Direction.Horizontal)
{
mFill = (mInverted ? FillDirection.RightToLeft : FillDirection.LeftToRight);
}
else
{
mFill = ((!mInverted) ? FillDirection.TopToBottom : FillDirection.BottomToTop);
}
mDir = Direction.Upgraded;
}
}
protected override void OnStart()
{
base.OnStart();
if (mFG != null && mFG.gameObject != base.gameObject && (mFG.GetComponent<Collider>() != null || mFG.GetComponent<Collider2D>() != null))
{
UIEventListener uIEventListener = UIEventListener.Get(mFG.gameObject);
UIEventListener uIEventListener2 = uIEventListener;
uIEventListener2.onPress = (UIEventListener.BoolDelegate)Delegate.Combine(uIEventListener2.onPress, new UIEventListener.BoolDelegate(base.OnPressForeground));
UIEventListener uIEventListener3 = uIEventListener;
uIEventListener3.onDrag = (UIEventListener.VectorDelegate)Delegate.Combine(uIEventListener3.onDrag, new UIEventListener.VectorDelegate(base.OnDragForeground));
mFG.autoResizeBoxCollider = true;
}
}
protected override float LocalToValue(Vector2 localPos)
{
if (mFG != null)
{
float num = Mathf.Clamp01(mSize) * 0.5f;
float t = num;
float t2 = 1f - num;
Vector3[] localCorners = mFG.localCorners;
if (base.isHorizontal)
{
t = Mathf.Lerp(localCorners[0].x, localCorners[2].x, t);
t2 = Mathf.Lerp(localCorners[0].x, localCorners[2].x, t2);
float num2 = t2 - t;
if (num2 == 0f)
{
return base.value;
}
return (!base.isInverted) ? ((localPos.x - t) / num2) : ((t2 - localPos.x) / num2);
}
t = Mathf.Lerp(localCorners[0].y, localCorners[1].y, t);
t2 = Mathf.Lerp(localCorners[3].y, localCorners[2].y, t2);
float num3 = t2 - t;
if (num3 == 0f)
{
return base.value;
}
return (!base.isInverted) ? ((localPos.y - t) / num3) : ((t2 - localPos.y) / num3);
}
return base.LocalToValue(localPos);
}
public override void ForceUpdate()
{
if (mFG != null)
{
mIsDirty = false;
float num = Mathf.Clamp01(mSize) * 0.5f;
float num2 = Mathf.Lerp(num, 1f - num, base.value);
float num3 = num2 - num;
float num4 = num2 + num;
if (base.isHorizontal)
{
mFG.drawRegion = ((!base.isInverted) ? new Vector4(num3, 0f, num4, 1f) : new Vector4(1f - num4, 0f, 1f - num3, 1f));
}
else
{
mFG.drawRegion = ((!base.isInverted) ? new Vector4(0f, num3, 1f, num4) : new Vector4(0f, 1f - num4, 1f, 1f - num3));
}
if (thumb != null)
{
Vector4 drawingDimensions = mFG.drawingDimensions;
Vector3 position = new Vector3(Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, 0.5f), Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, 0.5f));
SetThumbPosition(mFG.cachedTransform.TransformPoint(position));
}
}
else
{
base.ForceUpdate();
}
}
}