Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
PopperManager.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using DG.Tweening;
4using UnityEngine;
5
6public class PopperManager : MonoBehaviour
7{
8 public List<Popper> list = new List<Popper>();
9
10 public Popper Pop(Vector3 pos, string id, Sprite sprite)
11 {
12 Popper popper = Pop(pos, null, id);
13 popper.sr.sprite = sprite;
14 return popper;
15 }
16
17 public Popper Pop(Vector3 pos, string id = "Default")
18 {
19 return Pop(pos, null, id);
20 }
21
22 public Popper Pop(Func<Vector3> func, string id = "Default")
23 {
24 return Pop(func(), func, id);
25 }
26
27 public Popper Pop(Vector3 pos, Func<Vector3> func, string id = "Default")
28 {
29 Popper p = PoolManager.Spawn<Popper>("Popper" + id, "UI/Pop/Popper" + id);
30 p.SetActive(enable: true);
31 if (p.useLocalPosition)
32 {
33 p.anime.transform.localPosition = new Vector3(p.posFix.x + p.posRandom.x * UnityEngine.Random.Range(-1f, 1f), p.posFix.y + p.posRandom.y * UnityEngine.Random.Range(-1f, 1f), p.posFix.z - 0.01f * (float)list.Count);
34 }
35 else
36 {
37 p.anime.transform.position = new Vector3(pos.x + p.posFix.x + p.posRandom.x * UnityEngine.Random.Range(-1f, 1f), pos.y + p.posFix.y + p.posRandom.y * UnityEngine.Random.Range(-1f, 1f), pos.z + p.posFix.z - 0.01f * (float)list.Count);
38 }
39 p.anime.onComplete.AddListener(delegate
40 {
41 Kill(p);
42 });
43 if (func != null)
44 {
45 p.anime.onUpdate.AddListener(delegate
46 {
47 p.transform.position = func();
48 });
49 }
50 DOTweenAnimation[] componentsInChildren = p.GetComponentsInChildren<DOTweenAnimation>();
51 for (int i = 0; i < componentsInChildren.Length; i++)
52 {
53 componentsInChildren[i].DORestart(fromHere: true);
54 }
55 list.Add(p);
56 return p;
57 }
58
59 public void Kill(Popper p, bool removeFromList = true)
60 {
61 if (removeFromList)
62 {
63 list.Remove(p);
64 }
65 p.anime.onComplete.RemoveAllListeners();
66 if (p.anime.onUpdate != null)
67 {
68 p.anime.onUpdate.RemoveAllListeners();
69 }
70 if (p.anime.onPlay != null)
71 {
72 p.anime.onPlay.RemoveAllListeners();
73 }
74 TweenUtil.KillTween(ref p.tweenDelay);
76 }
77
78 public void KillAll()
79 {
80 foreach (Popper item in list)
81 {
82 Kill(item, removeFromList: false);
83 }
84 list.Clear();
85 }
86}
static void Despawn(Component c)
Definition: PoolManager.cs:128
static Transform Spawn(string id, string path, Transform parent)
Definition: PoolManager.cs:86
void Kill(Popper p, bool removeFromList=true)
List< Popper > list
Definition: PopperManager.cs:8
Popper Pop(Vector3 pos, string id, Sprite sprite)
Popper Pop(Vector3 pos, string id="Default")
Popper Pop(Func< Vector3 > func, string id="Default")
Popper Pop(Vector3 pos, Func< Vector3 > func, string id="Default")
Definition: Popper.cs:6
DOTweenAnimation anime
Definition: Popper.cs:12
Vector3 posFix
Definition: Popper.cs:16
Tween tweenDelay
Definition: Popper.cs:22
bool useLocalPosition
Definition: Popper.cs:20
Vector3 posRandom
Definition: Popper.cs:18