Elin Decompiled Documentation EA 23.268 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 }, delegate
107 {
108 Play(_from, fixY, _to, sprite);
109 });
110 }
111
112 public Effect Play(Point from, float fixY = 0f, Point to = null, Sprite sprite = null)
113 {
114 return _Play(from, from.Position(), fixY, to, sprite);
115 }
116
117 public Effect _Play(Point from, Vector3 fromV, float fixY = 0f, Point to = null, Sprite sprite = null)
118 {
120 {
121 Kill();
122 return null;
123 }
124 if ((bool)sprite)
125 {
126 sr.sprite = sprite;
127 }
128 if (setColor && from.IsValid)
129 {
130 float num = 0.07f * (float)(int)from.cell.light + EMono.core.screen.tileMap._baseBrightness;
131 num += ((from.cell.HasRoof || from.cell.isShadowed) ? (-0.2f) : 0f);
132 if ((bool)sr)
133 {
134 sr.material.SetVector("_Color", new Vector4(num, num, num, 1f));
135 }
136 }
137 fromV += posFix;
138 fromV.y += fixY;
139 if (to == null)
140 {
141 fromV += randomRange.Random();
142 }
143 this.fromV = fromV;
144 destPos = to ?? from;
145 base.transform.position = fromV;
146 if (randomFlip)
147 {
148 sr.flipX = EMono.rnd(2) == 0;
149 }
150 if (to != null)
151 {
152 float num2 = Mathf.Min(speed * (float)from.Distance(to), duration);
153 destV = to.Position() + posFix + randomRange.Random();
154 if (rotate)
155 {
156 base.transform.rotation = from.GetRotation(to);
157 }
158 moveTween = base.transform.DOMove(destV, num2).SetEase(Ease.Linear).SetDelay(startDelay);
159 }
160 Activate();
161 OnPlay();
162 OnUpdate();
163 return this;
164 }
165
166 public Effect Play(Vector3 v)
167 {
169 {
170 Kill();
171 return null;
172 }
173 fromV = v;
174 base.transform.position = fromV + posFix;
175 Activate();
176 OnPlay();
177 OnUpdate();
178 return this;
179 }
180
181 protected void Activate()
182 {
183 if (sprites.Length != 0 && type != Type.Firework)
184 {
185 sr.enabled = false;
186 }
187 manager.Add(this);
188 killTimer = TweenUtil.Tween(startDelay + duration + 0.01f + (float)sprites.Length * 0.01f, null, Kill);
189 }
190
191 public Effect Flip(bool x = false, bool y = false)
192 {
193 if ((bool)sr)
194 {
195 sr.flipX = (sr.flipX ? (!x) : x);
196 sr.flipY = (sr.flipY ? (!y) : y);
197 }
198 return this;
199 }
200
201 public Effect SetStartDelay(float a)
202 {
203 startDelay = a;
204 return this;
205 }
206
207 public virtual void OnPlay()
208 {
209 }
210
211 public virtual void OnUpdate()
212 {
213 if (!base.gameObject.activeSelf)
214 {
215 base.gameObject.SetActive(value: true);
216 }
217 timer += (randomSpeed ? UnityEngine.Random.Range(Time.deltaTime, Time.deltaTime * 1.5f) : Time.deltaTime);
218 if (startDelay != 0f)
219 {
220 if (timer < startDelay)
221 {
222 return;
223 }
224 timer = (startDelay = 0f);
225 }
226 if (sprites.Length != 0 && type != Type.Firework && timer > duration / (float)sprites.Length)
227 {
228 timer = 0f;
229 spriteIndex++;
230 if (spriteIndex >= sprites.Length)
231 {
232 Kill();
233 return;
234 }
235 sr.enabled = true;
236 sr.sprite = sprites[spriteIndex];
237 }
238 }
239
240 public void Kill()
241 {
242 TweenUtil.KillTween(ref killTimer);
243 TweenUtil.KillTween(ref moveTween);
244 killed = true;
245 OnKill();
246 manager.Remove(this);
248 {
249 PoolManager.DespawnOrDestroy(base.transform);
250 }
251 else if ((bool)base.gameObject)
252 {
253 UnityEngine.Object.Destroy(base.gameObject);
254 }
255 }
256
257 public virtual void OnKill()
258 {
259 }
260
261 public void OnDisable()
262 {
263 if ((bool)base.transform.parent && !test)
264 {
265 Kill();
266 }
267 }
268
269 public void OnDestroy()
270 {
271 if (materialsToDestroy == null)
272 {
273 return;
274 }
275 foreach (Material item in materialsToDestroy)
276 {
277 UnityEngine.Object.Destroy(item);
278 }
279 }
280
281 public Effect Emit(int num)
282 {
283 ParticleSystem[] array = systems;
284 for (int i = 0; i < array.Length; i++)
285 {
286 array[i].Emit(num);
287 }
288 return this;
289 }
290
292 {
293 ParticleSystem[] array = systems;
294 for (int i = 0; i < array.Length; i++)
295 {
296 ParticleSystem.MainModule main = array[i].main;
297 main.startColor = c;
298 }
299 return this;
300 }
301
302 public Effect SetParticleColor(Color color, bool changeMaterial = false, string idCol = "_Color")
303 {
304 if (changeMaterial)
305 {
306 materialsToDestroy = new List<Material>();
307 }
308 ParticleSystem[] array = systems;
309 foreach (ParticleSystem particleSystem in array)
310 {
311 if (changeMaterial)
312 {
313 Material material = particleSystem.GetComponent<ParticleSystemRenderer>().material;
315 material.SetColor(idCol, color);
316 }
317 else
318 {
319 ParticleSystem.MainModule main = particleSystem.main;
320 main.startColor = color;
321 }
322 }
323 return this;
324 }
325
326 public Effect SetScale(float a)
327 {
328 base.transform.localScale *= a;
329 return this;
330 }
331}
BaseTileMap tileMap
float _baseBrightness
Definition: BaseTileMap.cs:314
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:117
static EffectManager manager
Definition: Effect.cs:83
Tween killTimer
Definition: Effect.cs:81
virtual void OnUpdate()
Definition: Effect.cs:211
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:112
bool test
Definition: Effect.cs:48
ParticleSystem[] systems
Definition: Effect.cs:30
virtual void OnPlay()
Definition: Effect.cs:207
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:281
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:201
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:191
float duration
Definition: Effect.cs:16
Action onComplete
Definition: Effect.cs:52
void Kill()
Definition: Effect.cs:240
bool pooled
Definition: Effect.cs:67
Effect Play(Vector3 v)
Definition: Effect.cs:166
float timer
Definition: Effect.cs:58
Vector3 fromV
Definition: Effect.cs:61
bool pool
Definition: Effect.cs:26
void OnDisable()
Definition: Effect.cs:261
Effect SetParticleColor(Color c)
Definition: Effect.cs:291
bool randomSpeed
Definition: Effect.cs:46
virtual void OnKill()
Definition: Effect.cs:257
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:302
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:181
Effect SetScale(float a)
Definition: Effect.cs:326
Type
Definition: Effect.cs:9
void OnDestroy()
Definition: Effect.cs:269
Definition: Point.cs:9
ref Vector3 Position(int height)
Definition: Point.cs:548
Point Copy()
Definition: Point.cs:491
Quaternion GetRotation(Point to)
Definition: Point.cs:602
bool IsValid
Definition: Point.cs:88
int Distance(Point p)
Definition: Point.cs:989
Cell cell
Definition: Point.cs:51
static void DespawnOrDestroy(Component c)
Definition: PoolManager.cs:158