Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
Effect.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using DG.Tweening;
4using UnityEngine;
5
6public class Effect : SceneObject
7{
8 public enum Type
9 {
10 Default,
12 }
13
14 public Type type;
15
16 public float duration = 1f;
17
18 public float speed;
19
20 public float startDelay;
21
22 public bool lookAtTarget;
23
24 public bool rotate;
25
26 public bool pool;
27
28 public SpriteRenderer sr;
29
30 public ParticleSystem[] systems;
31
32 public Vector3[] dirs;
33
34 public Ease ease;
35
36 public Vector3 posFix;
37
38 public Vector3 randomRange;
39
40 public Tween moveTween;
41
42 public Sprite[] sprites;
43
44 public bool randomFlip;
45
46 public bool randomSpeed;
47
48 public bool test;
49
50 public bool setColor = true;
51
52 public Action onComplete;
53
54 [NonSerialized]
55 public int spriteIndex;
56
57 [NonSerialized]
58 public float timer;
59
60 [NonSerialized]
61 public Vector3 fromV;
62
63 [NonSerialized]
64 public Vector3 destV;
65
66 [NonSerialized]
67 public bool pooled;
68
69 [NonSerialized]
70 public Transform poolParent;
71
72 [NonSerialized]
73 public List<Material> materialsToDestroy;
74
75 [NonSerialized]
76 public Point destPos;
77
78 protected bool killed;
79
80 [NonSerialized]
81 public Tween killTimer;
82
84
85 public static Effect Get(Effect original)
86 {
87 return UnityEngine.Object.Instantiate(original);
88 }
89
90 public static Effect Get(string id)
91 {
92 return manager.effects.Get(id);
93 }
94
95 public static T Get<T>(string id) where T : Effect
96 {
97 return manager.effects.Get(id) as T;
98 }
99
100 public void Play(float delay, Point from, float fixY = 0f, Point to = null, Sprite sprite = null)
101 {
102 Point _from = from.Copy();
103 Point _to = to?.Copy() ?? null;
104 TweenUtil.Tween(delay, delegate
105 {
106 Play(_from, fixY, _to, sprite);
107 });
108 }
109
110 public Effect Play(Point from, float fixY = 0f, Point to = null, Sprite sprite = null)
111 {
112 return _Play(from, from.Position(), fixY, to, sprite);
113 }
114
115 public Effect _Play(Point from, Vector3 fromV, float fixY = 0f, Point to = null, Sprite sprite = null)
116 {
118 {
119 Kill();
120 return null;
121 }
122 if ((bool)sprite)
123 {
124 sr.sprite = sprite;
125 }
126 if (setColor)
127 {
128 float num = 0.07f * (float)(int)from.cell.light + EMono.core.screen.tileMap._baseBrightness;
129 num += ((from.cell.HasRoof || from.cell.isShadowed) ? (-0.2f) : 0f);
130 if ((bool)sr)
131 {
132 sr.material.SetVector("_Color", new Vector4(num, num, num, 1f));
133 }
134 }
135 fromV += posFix;
136 fromV.y += fixY;
137 if (to == null)
138 {
139 fromV += randomRange.Random();
140 }
141 this.fromV = fromV;
142 destPos = to ?? from;
143 base.transform.position = fromV;
144 if (randomFlip)
145 {
146 sr.flipX = EMono.rnd(2) == 0;
147 }
148 if (to != null)
149 {
150 float num2 = Mathf.Min(speed * (float)from.Distance(to), duration);
151 destV = to.Position() + posFix + randomRange.Random();
152 if (rotate)
153 {
154 base.transform.rotation = from.GetRotation(to);
155 }
156 moveTween = base.transform.DOMove(destV, num2).SetEase(Ease.Linear).SetDelay(startDelay);
157 }
158 Activate();
159 OnPlay();
160 OnUpdate();
161 return this;
162 }
163
164 public Effect Play(Vector3 v)
165 {
167 {
168 Kill();
169 return null;
170 }
171 fromV = v;
172 base.transform.position = fromV + posFix;
173 Activate();
174 OnPlay();
175 OnUpdate();
176 return this;
177 }
178
179 protected void Activate()
180 {
181 if (sprites.Length != 0 && type != Type.Firework)
182 {
183 sr.enabled = false;
184 }
185 manager.Add(this);
186 killTimer = TweenUtil.Tween(startDelay + duration + 0.01f + (float)sprites.Length * 0.01f, null, Kill);
187 }
188
189 public Effect Flip(bool x = false, bool y = false)
190 {
191 if ((bool)sr)
192 {
193 sr.flipX = (sr.flipX ? (!x) : x);
194 sr.flipY = (sr.flipY ? (!y) : y);
195 }
196 return this;
197 }
198
199 public Effect SetStartDelay(float a)
200 {
201 startDelay = a;
202 return this;
203 }
204
205 public virtual void OnPlay()
206 {
207 }
208
209 public virtual void OnUpdate()
210 {
211 if (!base.gameObject.activeSelf)
212 {
213 base.gameObject.SetActive(value: true);
214 }
215 timer += (randomSpeed ? UnityEngine.Random.Range(Time.deltaTime, Time.deltaTime * 1.5f) : Time.deltaTime);
216 if (startDelay != 0f)
217 {
218 if (timer < startDelay)
219 {
220 return;
221 }
222 timer = (startDelay = 0f);
223 }
224 if (sprites.Length != 0 && type != Type.Firework && timer > duration / (float)sprites.Length)
225 {
226 timer = 0f;
227 spriteIndex++;
228 if (spriteIndex >= sprites.Length)
229 {
230 Kill();
231 return;
232 }
233 sr.enabled = true;
234 sr.sprite = sprites[spriteIndex];
235 }
236 }
237
238 public void Kill()
239 {
240 TweenUtil.KillTween(ref killTimer);
241 TweenUtil.KillTween(ref moveTween);
242 killed = true;
243 OnKill();
244 manager.Remove(this);
246 {
247 PoolManager.DespawnOrDestroy(base.transform);
248 }
249 else if ((bool)base.gameObject)
250 {
251 UnityEngine.Object.Destroy(base.gameObject);
252 }
253 }
254
255 public virtual void OnKill()
256 {
257 }
258
259 public void OnDisable()
260 {
261 if ((bool)base.transform.parent && !test)
262 {
263 Kill();
264 }
265 }
266
267 public void OnDestroy()
268 {
269 if (materialsToDestroy == null)
270 {
271 return;
272 }
273 foreach (Material item in materialsToDestroy)
274 {
275 UnityEngine.Object.Destroy(item);
276 }
277 }
278
279 public Effect Emit(int num)
280 {
281 ParticleSystem[] array = systems;
282 for (int i = 0; i < array.Length; i++)
283 {
284 array[i].Emit(num);
285 }
286 return this;
287 }
288
290 {
291 ParticleSystem[] array = systems;
292 for (int i = 0; i < array.Length; i++)
293 {
294 ParticleSystem.MainModule main = array[i].main;
295 main.startColor = c;
296 }
297 return this;
298 }
299
300 public Effect SetParticleColor(Color color, bool changeMaterial = false, string idCol = "_Color")
301 {
302 if (changeMaterial)
303 {
304 materialsToDestroy = new List<Material>();
305 }
306 ParticleSystem[] array = systems;
307 foreach (ParticleSystem particleSystem in array)
308 {
309 if (changeMaterial)
310 {
311 Material material = particleSystem.GetComponent<ParticleSystemRenderer>().material;
313 material.SetColor(idCol, color);
314 }
315 else
316 {
317 ParticleSystem.MainModule main = particleSystem.main;
318 main.startColor = color;
319 }
320 }
321 return this;
322 }
323
324 public Effect SetScale(float a)
325 {
326 base.transform.localScale *= a;
327 return this;
328 }
329}
BaseTileMap tileMap
float _baseBrightness
Definition: BaseTileMap.cs:308
bool isShadowed
Definition: Cell.cs:246
BaseGameScreen screen
Definition: Core.cs:67
bool IsGameStarted
Definition: Core.cs:84
Definition: EMono.cs:4
static Core core
Definition: EMono.cs:5
static int rnd(int a)
Definition: EMono.cs:47
Effect Get(string id)
Definition: EffectManager.cs:9
EffectList effects
static EffectManager Instance
void Remove(Effect e)
void Add(Effect e)
Definition: Effect.cs:7
float speed
Definition: Effect.cs:18
static T Get< T >(string id)
Definition: Effect.cs:95
Effect _Play(Point from, Vector3 fromV, float fixY=0f, Point to=null, Sprite sprite=null)
Definition: Effect.cs:115
static EffectManager manager
Definition: Effect.cs:83
Tween killTimer
Definition: Effect.cs:81
virtual void OnUpdate()
Definition: Effect.cs:209
Point destPos
Definition: Effect.cs:76
Vector3[] dirs
Definition: Effect.cs:32
Effect Play(Point from, float fixY=0f, Point to=null, Sprite sprite=null)
Definition: Effect.cs:110
bool test
Definition: Effect.cs:48
ParticleSystem[] systems
Definition: Effect.cs:30
virtual void OnPlay()
Definition: Effect.cs:205
SpriteRenderer sr
Definition: Effect.cs:28
Sprite[] sprites
Definition: Effect.cs:42
Transform poolParent
Definition: Effect.cs:70
Effect Emit(int num)
Definition: Effect.cs:279
bool rotate
Definition: Effect.cs:24
static Effect Get(Effect original)
Definition: Effect.cs:85
static Effect Get(string id)
Definition: Effect.cs:90
bool lookAtTarget
Definition: Effect.cs:22
int spriteIndex
Definition: Effect.cs:55
bool killed
Definition: Effect.cs:78
bool randomFlip
Definition: Effect.cs:44
float startDelay
Definition: Effect.cs:20
Effect SetStartDelay(float a)
Definition: Effect.cs:199
Vector3 randomRange
Definition: Effect.cs:38
Ease ease
Definition: Effect.cs:34
void Play(float delay, Point from, float fixY=0f, Point to=null, Sprite sprite=null)
Definition: Effect.cs:100
Effect Flip(bool x=false, bool y=false)
Definition: Effect.cs:189
float duration
Definition: Effect.cs:16
Action onComplete
Definition: Effect.cs:52
void Kill()
Definition: Effect.cs:238
bool pooled
Definition: Effect.cs:67
Effect Play(Vector3 v)
Definition: Effect.cs:164
float timer
Definition: Effect.cs:58
Vector3 fromV
Definition: Effect.cs:61
bool pool
Definition: Effect.cs:26
void OnDisable()
Definition: Effect.cs:259
Effect SetParticleColor(Color c)
Definition: Effect.cs:289
bool randomSpeed
Definition: Effect.cs:46
virtual void OnKill()
Definition: Effect.cs:255
bool setColor
Definition: Effect.cs:50
Vector3 posFix
Definition: Effect.cs:36
Effect SetParticleColor(Color color, bool changeMaterial=false, string idCol="_Color")
Definition: Effect.cs:300
List< Material > materialsToDestroy
Definition: Effect.cs:73
Tween moveTween
Definition: Effect.cs:40
Type type
Definition: Effect.cs:14
Vector3 destV
Definition: Effect.cs:64
void Activate()
Definition: Effect.cs:179
Effect SetScale(float a)
Definition: Effect.cs:324
Type
Definition: Effect.cs:9
void OnDestroy()
Definition: Effect.cs:267
Definition: Point.cs:9
ref Vector3 Position(int height)
Definition: Point.cs:524
Point Copy()
Definition: Point.cs:467
Quaternion GetRotation(Point to)
Definition: Point.cs:578
int Distance(Point p)
Definition: Point.cs:953
Cell cell
Definition: Point.cs:51
static void DespawnOrDestroy(Component c)
Definition: PoolManager.cs:158