-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathTweenColor.cs
153 lines (137 loc) · 2.42 KB
/
TweenColor.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
using System;
using UnityEngine;
[AddComponentMenu("NGUI/Tween/Tween Color")]
public class TweenColor : UITweener
{
public Color from = Color.white;
public Color to = Color.white;
private bool mCached;
private UIWidget mWidget;
private Material mMat;
private Light mLight;
private SpriteRenderer mSr;
[Obsolete("Use 'value' instead")]
public Color color
{
get
{
return value;
}
set
{
this.value = value;
}
}
public Color value
{
get
{
if (!mCached)
{
Cache();
}
if (mWidget != null)
{
return mWidget.color;
}
if (mMat != null)
{
return mMat.color;
}
if (mSr != null)
{
return mSr.color;
}
if (mLight != null)
{
return mLight.color;
}
return Color.black;
}
set
{
if (!mCached)
{
Cache();
}
if (mWidget != null)
{
mWidget.color = value;
}
else if (mMat != null)
{
mMat.color = value;
}
else if (mSr != null)
{
mSr.color = value;
}
else if (mLight != null)
{
mLight.color = value;
mLight.enabled = (value.r + value.g + value.b > 0.01f);
}
}
}
private void Cache()
{
mCached = true;
mWidget = GetComponent<UIWidget>();
if (!(mWidget != null))
{
mSr = GetComponent<SpriteRenderer>();
if (!(mSr != null))
{
Renderer component = GetComponent<Renderer>();
if (component != null)
{
mMat = component.material;
}
else
{
mLight = GetComponent<Light>();
if (mLight == null)
{
mWidget = GetComponentInChildren<UIWidget>();
}
}
}
}
}
protected override void OnUpdate(float factor, bool isFinished)
{
value = Color.Lerp(from, to, factor);
}
public static TweenColor Begin(GameObject go, float duration, Color color)
{
TweenColor tweenColor = UITweener.Begin<TweenColor>(go, duration);
tweenColor.from = tweenColor.value;
tweenColor.to = color;
if (duration <= 0f)
{
tweenColor.Sample(1f, isFinished: true);
tweenColor.enabled = false;
}
return tweenColor;
}
[ContextMenu("Set 'From' to current value")]
public override void SetStartToCurrentValue()
{
from = value;
}
[ContextMenu("Set 'To' to current value")]
public override void SetEndToCurrentValue()
{
to = value;
}
[ContextMenu("Assume value of 'From'")]
private void SetCurrentValueToStart()
{
value = from;
}
[ContextMenu("Assume value of 'To'")]
private void SetCurrentValueToEnd()
{
value = to;
}
}