Elin Decompiled Documentation EA 23.321 Nightly Patch 1
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 Vector3 orgLocalScale;
68
69 [NonSerialized]
70 public List<Material> materialsToDestroy;
71
72 [NonSerialized]
73 public Point destPos;
74
75 [NonSerialized]
76 public Tween killTimer;
77
79
80 public static Effect Get(Effect original)
81 {
82 return UnityEngine.Object.Instantiate(original);
83 }
84
85 public static Effect Get(string id)
86 {
87 return manager.effects.Get(id);
88 }
89
90 public static T Get<T>(string id) where T : Effect
91 {
92 return manager.effects.Get(id) as T;
93 }
94
95 private void Awake()
96 {
97 orgLocalScale = base.transform.localScale;
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 timer = 0f;
245 spriteIndex = 0;
246 base.transform.localScale = orgLocalScale;
247 OnKill();
248 manager.Remove(this);
250 {
251 PoolManager.DespawnOrDestroy(base.transform);
252 }
253 else if ((bool)base.gameObject)
254 {
255 UnityEngine.Object.Destroy(base.gameObject);
256 }
257 }
258
259 public virtual void OnKill()
260 {
261 }
262
263 public void OnDisable()
264 {
265 if ((bool)base.transform.parent && !test && (!pool || !manager.effects.usePool))
266 {
267 Kill();
268 }
269 }
270
271 public void OnDestroy()
272 {
273 if (materialsToDestroy == null)
274 {
275 return;
276 }
277 foreach (Material item in materialsToDestroy)
278 {
279 UnityEngine.Object.Destroy(item);
280 }
281 }
282
283 public Effect Emit(int num)
284 {
285 ParticleSystem[] array = systems;
286 for (int i = 0; i < array.Length; i++)
287 {
288 array[i].Emit(num);
289 }
290 return this;
291 }
292
294 {
295 ParticleSystem[] array = systems;
296 for (int i = 0; i < array.Length; i++)
297 {
298 ParticleSystem.MainModule main = array[i].main;
299 main.startColor = c;
300 }
301 return this;
302 }
303
304 public Effect SetParticleColor(Color color, bool changeMaterial = false, string idCol = "_Color")
305 {
306 if (changeMaterial)
307 {
308 materialsToDestroy = new List<Material>();
309 }
310 ParticleSystem[] array = systems;
311 foreach (ParticleSystem particleSystem in array)
312 {
313 if (changeMaterial)
314 {
315 Material material = particleSystem.GetComponent<ParticleSystemRenderer>().material;
316 if (!manager.effects.usePool || !pool)
317 {
319 }
320 material.SetColor(idCol, color);
321 }
322 else
323 {
324 ParticleSystem.MainModule main = particleSystem.main;
325 main.startColor = color;
326 }
327 }
328 return this;
329 }
330
331 public Effect SetScale(float a)
332 {
333 base.transform.localScale *= a;
334 return this;
335 }
336}
BaseTileMap tileMap
float _baseBrightness
Definition: BaseTileMap.cs:314
bool isShadowed
Definition: Cell.cs:254
BaseGameScreen screen
Definition: Core.cs:67
bool IsGameStarted
Definition: Core.cs:87
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:90
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:78
Tween killTimer
Definition: Effect.cs:76
virtual void OnUpdate()
Definition: Effect.cs:211
Point destPos
Definition: Effect.cs:73
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
Effect Emit(int num)
Definition: Effect.cs:283
bool rotate
Definition: Effect.cs:24
static Effect Get(Effect original)
Definition: Effect.cs:80
static Effect Get(string id)
Definition: Effect.cs:85
bool lookAtTarget
Definition: Effect.cs:22
int spriteIndex
Definition: Effect.cs:55
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
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:263
void Awake()
Definition: Effect.cs:95
Vector3 orgLocalScale
Definition: Effect.cs:67
Effect SetParticleColor(Color c)
Definition: Effect.cs:293
bool randomSpeed
Definition: Effect.cs:46
virtual void OnKill()
Definition: Effect.cs:259
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:304
List< Material > materialsToDestroy
Definition: Effect.cs:70
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:331
Type
Definition: Effect.cs:9
void OnDestroy()
Definition: Effect.cs:271
Definition: Point.cs:9
ref Vector3 Position(int height)
Definition: Point.cs:553
Point Copy()
Definition: Point.cs:491
Quaternion GetRotation(Point to)
Definition: Point.cs:607
bool IsValid
Definition: Point.cs:88
int Distance(Point p)
Definition: Point.cs:995
Cell cell
Definition: Point.cs:51
static void DespawnOrDestroy(Component c)
Definition: PoolManager.cs:158