-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathSpringPanel.cs
78 lines (66 loc) · 1.7 KB
/
SpringPanel.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
using UnityEngine;
[AddComponentMenu("NGUI/Internal/Spring Panel")]
[RequireComponent(typeof(UIPanel))]
public class SpringPanel : MonoBehaviour
{
public delegate void OnFinished();
public static SpringPanel current;
public Vector3 target = Vector3.zero;
public float strength = 10f;
public OnFinished onFinished;
private UIPanel mPanel;
private Transform mTrans;
private UIScrollView mDrag;
private void Start()
{
mPanel = GetComponent<UIPanel>();
mDrag = GetComponent<UIScrollView>();
mTrans = base.transform;
}
private void Update()
{
AdvanceTowardsPosition();
}
protected virtual void AdvanceTowardsPosition()
{
float deltaTime = RealTime.deltaTime;
bool flag = false;
Vector3 localPosition = mTrans.localPosition;
Vector3 vector = NGUIMath.SpringLerp(mTrans.localPosition, target, strength, deltaTime);
if ((vector - target).sqrMagnitude < 0.01f)
{
vector = target;
base.enabled = false;
flag = true;
}
mTrans.localPosition = vector;
Vector3 vector2 = vector - localPosition;
Vector2 clipOffset = mPanel.clipOffset;
clipOffset.x -= vector2.x;
clipOffset.y -= vector2.y;
mPanel.clipOffset = clipOffset;
if (mDrag != null)
{
mDrag.UpdateScrollbars(recalculateBounds: false);
}
if (flag && onFinished != null)
{
current = this;
onFinished();
current = null;
}
}
public static SpringPanel Begin(GameObject go, Vector3 pos, float strength)
{
SpringPanel springPanel = go.GetComponent<SpringPanel>();
if (springPanel == null)
{
springPanel = go.AddComponent<SpringPanel>();
}
springPanel.target = pos;
springPanel.strength = strength;
springPanel.onFinished = null;
springPanel.enabled = true;
return springPanel;
}
}