-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathTweenAlpha.cs
134 lines (121 loc) · 2.05 KB
/
TweenAlpha.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
using System;
using UnityEngine;
[AddComponentMenu("NGUI/Tween/Tween Alpha")]
public class TweenAlpha : UITweener
{
[Range(0f, 1f)]
public float from = 1f;
[Range(0f, 1f)]
public float to = 1f;
private bool mCached;
private UIRect mRect;
private Material mMat;
private SpriteRenderer mSr;
[Obsolete("Use 'value' instead")]
public float alpha
{
get
{
return value;
}
set
{
this.value = value;
}
}
public float value
{
get
{
if (!mCached)
{
Cache();
}
if (mRect != null)
{
return mRect.alpha;
}
if (!(mSr != null))
{
float result;
if (mMat != null)
{
Color color = mMat.color;
result = color.a;
}
else
{
result = 1f;
}
return result;
}
Color color2 = mSr.color;
return color2.a;
}
set
{
if (!mCached)
{
Cache();
}
if (mRect != null)
{
mRect.alpha = value;
}
else if (mSr != null)
{
Color color = mSr.color;
color.a = value;
mSr.color = color;
}
else if (mMat != null)
{
Color color2 = mMat.color;
color2.a = value;
mMat.color = color2;
}
}
}
private void Cache()
{
mCached = true;
mRect = GetComponent<UIRect>();
mSr = GetComponent<SpriteRenderer>();
if (mRect == null && mSr == null)
{
Renderer component = GetComponent<Renderer>();
if (component != null)
{
mMat = component.material;
}
if (mMat == null)
{
mRect = GetComponentInChildren<UIRect>();
}
}
}
protected override void OnUpdate(float factor, bool isFinished)
{
value = Mathf.Lerp(from, to, factor);
}
public static TweenAlpha Begin(GameObject go, float duration, float alpha)
{
TweenAlpha tweenAlpha = UITweener.Begin<TweenAlpha>(go, duration);
tweenAlpha.from = tweenAlpha.value;
tweenAlpha.to = alpha;
if (duration <= 0f)
{
tweenAlpha.Sample(1f, isFinished: true);
tweenAlpha.enabled = false;
}
return tweenAlpha;
}
public override void SetStartToCurrentValue()
{
from = value;
}
public override void SetEndToCurrentValue()
{
to = value;
}
}