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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class Effects
{
private static HashSet<Transform> activeShakes = new HashSet<Transform>();
public static IEnumerator Wait(float duration)
{
for (float t = 0f; t < duration; t += Time.deltaTime)
{
yield return null;
}
yield break;
}
public static IEnumerator All(params IEnumerator[] items)
{
Stack<IEnumerator>[] enums = new Stack<IEnumerator>[items.Length];
for (int i = 0; i < items.Length; i++)
{
enums[i] = new Stack<IEnumerator>();
enums[i].Push(items[i]);
}
int num;
for (int cap = 0; cap < 100000; cap = num)
{
bool flag = false;
for (int j = 0; j < enums.Length; j++)
{
if (enums[j].Count > 0)
{
flag = true;
IEnumerator enumerator = enums[j].Peek();
if (enumerator.MoveNext())
{
if (enumerator.Current is IEnumerator)
{
enums[j].Push((IEnumerator)enumerator.Current);
}
}
else
{
enums[j].Pop();
}
}
}
if (!flag)
{
break;
}
yield return null;
num = cap + 1;
}
yield break;
}
internal static IEnumerator ScaleIn(Transform self, float source, float target, float duration)
{
if (!self)
{
yield break;
}
Vector3 localScale = default(Vector3);
for (float t = 0f; t < duration; t += Time.deltaTime)
{
localScale.x = (localScale.y = (localScale.z = Mathf.SmoothStep(source, target, t / duration)));
self.localScale = localScale;
yield return null;
}
localScale.z = target;
localScale.y = target;
localScale.x = target;
self.localScale = localScale;
yield break;
}
internal static IEnumerator CycleColors(SpriteRenderer self, Color source, Color target, float rate, float duration)
{
if (!self)
{
yield break;
}
self.enabled = true;
for (float t = 0f; t < duration; t += Time.deltaTime)
{
float t2 = Mathf.Sin(t * 3.1415927f / rate) / 2f + 0.5f;
self.color = Color.Lerp(source, target, t2);
yield return null;
}
self.color = source;
yield break;
}
internal static IEnumerator PulseColor(SpriteRenderer self, Color source, Color target, float duration = 0.5f)
{
if (!self)
{
yield break;
}
self.enabled = true;
for (float t = 0f; t < duration; t += Time.deltaTime)
{
self.color = Color.Lerp(target, source, t / duration);
yield return null;
}
self.color = source;
yield break;
}
internal static IEnumerator PulseColor(TextRenderer self, Color source, Color target, float duration = 0.5f)
{
if (!self)
{
yield break;
}
for (float t = 0f; t < duration; t += Time.deltaTime)
{
self.Color = Color.Lerp(target, source, t / duration);
yield return null;
}
self.Color = source;
yield break;
}
public static IEnumerator ColorFade(SpriteRenderer self, Color source, Color target, float duration)
{
if (!self)
{
yield break;
}
self.enabled = true;
for (float t = 0f; t < duration; t += Time.deltaTime)
{
self.color = Color.Lerp(source, target, t / duration);
yield return null;
}
self.color = target;
yield break;
}
public static IEnumerator Rotate2D(Transform target, float source, float dest, float duration = 0.75f)
{
Vector3 temp = target.localEulerAngles;
for (float time = 0f; time < duration; time += Time.deltaTime)
{
float t = time / duration;
temp.z = Mathf.SmoothStep(source, dest, t);
target.localEulerAngles = temp;
yield return null;
}
temp.z = dest;
target.localEulerAngles = temp;
yield break;
}
public static IEnumerator Slide2D(Transform target, Vector2 source, Vector2 dest, float duration = 0.75f)
{
Vector3 temp = default(Vector3);
temp.z = target.localPosition.z;
for (float time = 0f; time < duration; time += Time.deltaTime)
{
float t = time / duration;
temp.x = Mathf.SmoothStep(source.x, dest.x, t);
temp.y = Mathf.SmoothStep(source.y, dest.y, t);
target.localPosition = temp;
yield return null;
}
temp.x = dest.x;
temp.y = dest.y;
target.localPosition = temp;
yield break;
}
public static IEnumerator Bounce(Transform target, float duration = 0.3f, float height = 0.15f)
{
if (!target)
{
yield break;
}
Vector3 origin = target.localPosition;
Vector3 temp = origin;
for (float timer = 0f; timer < duration; timer += Time.deltaTime)
{
float num = timer / duration;
float num2 = 1f - num;
temp.y = origin.y + height * Mathf.Abs(Mathf.Sin(num * 3.1415927f * 3f)) * num2;
if (!target)
{
yield break;
}
target.localPosition = temp;
yield return null;
}
if (target)
{
target.transform.localPosition = origin;
}
yield break;
}
public static IEnumerator Shake(Transform target, float duration = 0.75f, float halfWidth = 0.25f)
{
if (Effects.activeShakes.Add(target))
{
Vector3 origin = target.localPosition;
for (float timer = 0f; timer < duration; timer += Time.deltaTime)
{
float num = timer / duration;
target.localPosition = origin + Vector3.right * (halfWidth * Mathf.Sin(num * 30f) * (1f - num));
yield return null;
}
target.transform.localPosition = origin;
Effects.activeShakes.Remove(target);
origin = default(Vector3);
}
yield break;
}
public static IEnumerator Bloop(float delay, Transform target, float duration = 0.5f)
{
for (float t = 0f; t < delay; t += Time.deltaTime)
{
yield return null;
}
Vector3 localScale = default(Vector3);
for (float t = 0f; t < duration; t += Time.deltaTime)
{
float z = Effects.ElasticOut(t, duration);
localScale.x = (localScale.y = (localScale.z = z));
target.localScale = localScale;
yield return null;
}
localScale.x = (localScale.y = (localScale.z = 1f));
target.localScale = localScale;
yield break;
}
private static float ElasticOut(float time, float duration)
{
time /= duration;
float num = time * time;
float num2 = num * time;
return 33f * num2 * num + -106f * num * num + 126f * num2 + -67f * num + 15f * time;
}
}
|