Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
Popfab.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using DG.Tweening;
3using UnityEngine;
4
5public class Popfab : MonoBehaviour
6{
7 public float fixX;
8
9 public float fixY;
10
11 public float spacing = 10f;
12
13 public bool invert;
14
15 public int maxItems;
16
17 public Ease pushEase = Ease.Linear;
18
19 public float pushDuration = 0.5f;
20
21 private Transform _trans;
22
23 [HideInInspector]
24 public List<PopfabItem> list = new List<PopfabItem>();
25
26 protected virtual void Awake()
27 {
28 _trans = base.transform;
29 }
30
31 public T Pop<T>(string id) where T : PopfabItem
32 {
33 return Util.Instantiate(ResourceCache.Load<T>("UI/Pop/" + id), this);
34 }
35
36 public PopfabItem Pop(string id, string text = null)
37 {
38 PopfabItem popfabItem = ResourceCache.Load<PopfabItem>("UI/Pop/" + id);
39 popfabItem.Set(text);
40 return Pop(popfabItem);
41 }
42
44 {
45 item.Init(_trans);
46 if (maxItems > 0)
47 {
48 item.isUseDuration = false;
49 }
50 if (pushEase != 0 && list.Count > 0)
51 {
52 PushItems(new Vector3(0f, item.rect.sizeDelta.y + spacing, 0f));
53 }
54 list.Add(item);
55 item.reciever = this;
56 if (maxItems != 0 && list.Count >= maxItems)
57 {
58 for (int i = 0; i < list.Count - maxItems; i++)
59 {
60 if (!list[i].isOutro)
61 {
62 list[i].Outro();
63 }
64 }
65 }
66 item.Intro();
67 return item;
68 }
69
70 public void Remove(PopfabItem item)
71 {
72 list.Remove(item);
73 }
74
75 public void Clear()
76 {
77 for (int num = list.Count - 1; num >= 0; num--)
78 {
79 list[num].Kill();
80 }
81 }
82
83 public void ForceOutro()
84 {
85 foreach (PopfabItem item in list)
86 {
87 item.ForceOutro();
88 }
89 }
90
91 public void PushItems(Vector3 pos)
92 {
93 if (invert)
94 {
95 pos *= -1f;
96 }
97 foreach (PopfabItem item in list)
98 {
99 item.destY += pos.y;
100 item.rect.DOLocalMoveY(item.destY, pushDuration).SetEase(pushEase);
101 }
102 }
103
104 private void OnDestroy()
105 {
106 for (int num = base.transform.childCount - 1; num >= 0; num--)
107 {
108 _trans.GetChild(num).GetComponent<PopfabItem>().Kill();
109 }
110 }
111}
void Set(string text)
Definition: PopfabItem.cs:83
Definition: Popfab.cs:6
virtual void Awake()
Definition: Popfab.cs:26
float fixY
Definition: Popfab.cs:9
void PushItems(Vector3 pos)
Definition: Popfab.cs:91
int maxItems
Definition: Popfab.cs:15
T Pop< T >(string id)
Definition: Popfab.cs:31
Ease pushEase
Definition: Popfab.cs:17
Transform _trans
Definition: Popfab.cs:21
void OnDestroy()
Definition: Popfab.cs:104
float spacing
Definition: Popfab.cs:11
float fixX
Definition: Popfab.cs:7
void ForceOutro()
Definition: Popfab.cs:83
void Remove(PopfabItem item)
Definition: Popfab.cs:70
List< PopfabItem > list
Definition: Popfab.cs:24
bool invert
Definition: Popfab.cs:13
PopfabItem Pop(PopfabItem item)
Definition: Popfab.cs:43
void Clear()
Definition: Popfab.cs:75
float pushDuration
Definition: Popfab.cs:19
PopfabItem Pop(string id, string text=null)
Definition: Popfab.cs:36