-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathTweenTransform.cs
67 lines (57 loc) · 1.58 KB
/
TweenTransform.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
using UnityEngine;
[AddComponentMenu("NGUI/Tween/Tween Transform")]
public class TweenTransform : UITweener
{
public Transform from;
public Transform to;
public bool parentWhenFinished;
private Transform mTrans;
private Vector3 mPos;
private Quaternion mRot;
private Vector3 mScale;
protected override void OnUpdate(float factor, bool isFinished)
{
if (to != null)
{
if (mTrans == null)
{
mTrans = base.transform;
mPos = mTrans.position;
mRot = mTrans.rotation;
mScale = mTrans.localScale;
}
if (from != null)
{
mTrans.position = from.position * (1f - factor) + to.position * factor;
mTrans.localScale = from.localScale * (1f - factor) + to.localScale * factor;
mTrans.rotation = Quaternion.Slerp(from.rotation, to.rotation, factor);
}
else
{
mTrans.position = mPos * (1f - factor) + to.position * factor;
mTrans.localScale = mScale * (1f - factor) + to.localScale * factor;
mTrans.rotation = Quaternion.Slerp(mRot, to.rotation, factor);
}
if (parentWhenFinished && isFinished)
{
mTrans.parent = to;
}
}
}
public static TweenTransform Begin(GameObject go, float duration, Transform to)
{
return Begin(go, duration, null, to);
}
public static TweenTransform Begin(GameObject go, float duration, Transform from, Transform to)
{
TweenTransform tweenTransform = UITweener.Begin<TweenTransform>(go, duration);
tweenTransform.from = from;
tweenTransform.to = to;
if (duration <= 0f)
{
tweenTransform.Sample(1f, isFinished: true);
tweenTransform.enabled = false;
}
return tweenTransform;
}
}