Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
PopManager.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using DG.Tweening;
4using UnityEngine;
5using UnityEngine.UI;
6
7public class PopManager : MonoBehaviour
8{
9 public static int outlineAlpha;
10
11 public int maxLines;
12
13 public Vector2 dir;
14
15 public Vector2 align;
16
17 public Vector2 spacing;
18
19 public Vector2 startPos;
20
21 public float durationMove;
22
23 public float durationActive;
24
25 public Ease ease;
26
27 public bool startAtDestPos;
28
29 public bool insert;
30
31 public bool ignoreDestPos;
32
33 [NonSerialized]
34 public List<PopItem> items = new List<PopItem>();
35
36 public T Get<T>(string id) where T : PopItem
37 {
38 return Util.Instantiate<T>("UI/Pop/" + id, this);
39 }
40
41 public PopItemText PopText(string text, Sprite sprite = null, string id = "PopText", Color c = default(Color), Vector3 destPos = default(Vector3), float duration = 0f)
42 {
43 PopItemText popItemText = Get<PopItemText>(id);
44 popItemText.important = false;
45 popItemText.SetText(text, sprite, c);
46 Pop(popItemText, destPos, duration);
47 return popItemText;
48 }
49
50 public PopItem Pop(PopItem item, Vector3 destPos = default(Vector3), float duration = 0f)
51 {
52 Text[] componentsInChildren = item.GetComponentsInChildren<Text>();
53 for (int i = 0; i < componentsInChildren.Length; i++)
54 {
55 componentsInChildren[i].RebuildLayout();
56 }
57 item.RebuildLayout();
58 if (insert)
59 {
60 items.Insert(0, item);
61 }
62 else
63 {
64 items.Add(item);
65 }
66 RectTransform rectTransform = item.Rect();
67 if (!ignoreDestPos)
68 {
69 UnityEngine.Object.Destroy(item.GetComponent<UIFollow>());
71 Vector2 anchoredPosition = (startAtDestPos ? item.destPos : new Vector2(rectTransform.rect.width * align.x, rectTransform.rect.height * align.y));
72 anchoredPosition += startPos;
73 rectTransform.anchoredPosition = anchoredPosition;
74 for (int j = 0; j < items.Count; j++)
75 {
76 items[j].Rect().DOAnchorPos(items[j].destPos, durationMove).SetEase(ease);
77 }
78 }
79 else
80 {
81 UIFollow uIFollow = item.GetComponent<UIFollow>();
82 if (!uIFollow)
83 {
84 uIFollow = item.gameObject.AddComponent<UIFollow>();
85 }
86 uIFollow.followPos = true;
87 uIFollow.fixPos = destPos;
88 rectTransform.anchoredPosition = Camera.main.WorldToScreenPoint(destPos) / BaseCore.Instance.uiScale;
89 }
90 if ((bool)item.animeIn)
91 {
92 item.animeIn.Play(item.transform);
93 }
94 item.killTimer = TweenUtil.Tween(((duration == 0f) ? 1f : duration) * durationActive + durationMove, null, delegate
95 {
96 Kill(item);
97 });
98 base.enabled = true;
99 return item;
100 }
101
102 private void Update()
103 {
104 if (items.Count == 0)
105 {
106 base.enabled = false;
107 }
108 if (maxLines != 0 && items.Count > maxLines)
109 {
110 if (insert)
111 {
112 Kill(items.LastItem());
113 }
114 else
115 {
116 Kill(items[0]);
117 }
118 }
119 }
120
121 public void UpdateDestPos()
122 {
123 Vector2 zero = Vector2.zero;
124 for (int i = 0; i < items.Count; i++)
125 {
126 Rect rect = items[i].Rect().rect;
127 zero.x += rect.width * dir.x + spacing.x;
128 zero.y += rect.height * dir.y + spacing.y;
129 items[i].destPos = zero + new Vector2(rect.width * align.x, rect.height * align.y);
130 if ((bool)items[i].arrow)
131 {
132 items[i].arrow.enabled = i == 0;
133 }
134 }
135 }
136
137 public void Kill(PopItem item, bool instant = false)
138 {
139 if (item.important)
140 {
141 return;
142 }
143 TweenUtil.KillTween(ref item.killTimer);
144 if (!instant && (bool)item.animeOut)
145 {
146 if (!item.isDying)
147 {
148 item.isDying = true;
149 item.animeOut.Play(item.transform).OnComplete(delegate
150 {
151 _Kill(item);
152 });
153 }
154 }
155 else
156 {
157 _Kill(item);
158 }
159 }
160
161 private void _Kill(PopItem item)
162 {
163 if (item == null || item.gameObject == null)
164 {
165 return;
166 }
167 DOTween.Kill(item.Rect());
168 UnityEngine.Object.Destroy(item.gameObject);
169 items.Remove(item);
170 if (!ignoreDestPos)
171 {
173 for (int i = 0; i < items.Count; i++)
174 {
175 items[i].Rect().DOAnchorPos(items[i].destPos, durationMove).SetEase(ease);
176 }
177 }
178 }
179
180 public void CopyAll(RectTransform rect)
181 {
182 foreach (PopItem item in items)
183 {
184 ContentSizeFitter[] componentsInChildren = item.GetComponentsInChildren<ContentSizeFitter>();
185 for (int i = 0; i < componentsInChildren.Length; i++)
186 {
187 componentsInChildren[i].enabled = false;
188 }
189 LayoutGroup[] componentsInChildren2 = item.GetComponentsInChildren<LayoutGroup>();
190 for (int i = 0; i < componentsInChildren2.Length; i++)
191 {
192 componentsInChildren2[i].enabled = false;
193 }
194 GameObject go = UnityEngine.Object.Instantiate(item.gameObject);
195 go.transform.SetParent(rect, worldPositionStays: false);
196 go.transform.position = item.transform.position;
197 Vector3 fixPos = Camera.main.ScreenToWorldPoint(go.transform.Rect().anchoredPosition * BaseCore.Instance.uiScale);
198 UIFollow uIFollow = go.AddComponent<UIFollow>();
199 uIFollow.followPos = true;
200 uIFollow.fixPos = fixPos;
201 uIFollow.LateUpdate();
202 go.AddComponent<CanvasGroup>().DOFade(0f, 1.5f).SetDelay(0.5f)
203 .OnComplete(delegate
204 {
205 if (go != null)
206 {
207 UnityEngine.Object.Destroy(go);
208 }
209 });
210 }
211 }
212
213 public void KillAll(bool instant = false)
214 {
215 if (instant)
216 {
217 foreach (PopItem item in items)
218 {
219 TweenUtil.KillTween(ref item.killTimer);
220 DOTween.Kill(item.Rect());
221 UnityEngine.Object.Destroy(item.gameObject);
222 }
223 items.Clear();
224 }
225 else
226 {
227 for (int num = items.Count - 1; num >= 0; num--)
228 {
229 Kill(items[num], instant);
230 }
231 }
232 }
233}
virtual float uiScale
Definition: BaseCore.cs:46
static BaseCore Instance
Definition: BaseCore.cs:11
void SetText(string s, Sprite sprite=null, Color c=default(Color))
Definition: PopItemText.cs:14
Vector2 spacing
Definition: PopManager.cs:17
void UpdateDestPos()
Definition: PopManager.cs:121
float durationActive
Definition: PopManager.cs:23
List< PopItem > items
Definition: PopManager.cs:34
void Kill(PopItem item, bool instant=false)
Definition: PopManager.cs:137
Ease ease
Definition: PopManager.cs:25
void CopyAll(RectTransform rect)
Definition: PopManager.cs:180
T Get< T >(string id)
Definition: PopManager.cs:36
float durationMove
Definition: PopManager.cs:21
bool ignoreDestPos
Definition: PopManager.cs:31
void Update()
Definition: PopManager.cs:102
Vector2 startPos
Definition: PopManager.cs:19
static int outlineAlpha
Definition: PopManager.cs:9
bool startAtDestPos
Definition: PopManager.cs:27
int maxLines
Definition: PopManager.cs:11
PopItemText PopText(string text, Sprite sprite=null, string id="PopText", Color c=default(Color), Vector3 destPos=default(Vector3), float duration=0f)
Definition: PopManager.cs:41
void KillAll(bool instant=false)
Definition: PopManager.cs:213
Vector2 align
Definition: PopManager.cs:15
bool insert
Definition: PopManager.cs:29
PopItem Pop(PopItem item, Vector3 destPos=default(Vector3), float duration=0f)
Definition: PopManager.cs:50
Vector2 dir
Definition: PopManager.cs:13
void _Kill(PopItem item)
Definition: PopManager.cs:161
void LateUpdate()
Definition: UIFollow.cs:19