Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
PopfabItem.cs
Go to the documentation of this file.
1using System;
2using DG.Tweening;
3using UnityEngine;
4using UnityEngine.UI;
5
6public class PopfabItem : MonoBehaviour
7{
8 public Transform animeTarget;
9
10 public CanvasGroup animeGroup;
11
12 public Anime intro;
13
14 public Anime outro;
15
17
18 public Anime loop;
19
20 public float duration = 6f;
21
22 public bool pooling;
23
24 public Vector3 fixPos = Vector3.zero;
25
26 private bool isKilled;
27
28 public bool startTransparent;
29
30 public bool clamp;
31
32 [Header("For Canvas")]
33 public Text uiText;
34
35 public bool screenSpace = true;
36
37 public ContentSizeFitter fitter;
38
39 public Image icon;
40
41 public bool stopFollow;
42
43 [NonSerialized]
44 public float destX;
45
46 [NonSerialized]
47 public float destY;
48
49 [NonSerialized]
50 public RectTransform rect;
51
52 [NonSerialized]
54
55 [NonSerialized]
56 public float destTime;
57
58 [NonSerialized]
59 public bool isOutro;
60
61 [NonSerialized]
62 public Transform followTarget;
63
64 [NonSerialized]
65 private Vector3? lastPosition;
66
67 [NonSerialized]
68 public bool isUseDuration = true;
69
70 [NonSerialized]
71 public bool hasRect;
72
73 private void Awake()
74 {
75 rect = base.transform as RectTransform;
76 hasRect = rect;
77 if (animeTarget == null)
78 {
80 }
81 }
82
83 public void Set(string text)
84 {
85 if ((bool)uiText)
86 {
87 uiText.text = text;
88 }
89 }
90
91 public void Set(BalloonData data)
92 {
93 Set(data.text);
94 if (data.font != null && (bool)uiText)
95 {
96 uiText.font = data.font;
97 }
98 if (data.fontSize != 0 && (bool)uiText)
99 {
100 uiText.fontSize = data.fontSize;
101 }
102 }
103
104 public void Init(Transform parent = null)
105 {
106 if ((bool)parent)
107 {
108 base.transform.SetParent(parent, worldPositionStays: false);
109 }
110 animeTarget.localScale = Vector3.one;
111 animeTarget.localEulerAngles = Vector3.zero;
112 animeTarget.localPosition = new Vector3(0f, 0f, animeTarget.localPosition.z);
113 if (stopFollow && (bool)followTarget)
114 {
115 lastPosition = followTarget.position;
116 }
117 if (fitter != null)
118 {
119 fitter.SetLayoutHorizontal();
120 fitter.SetLayoutVertical();
121 }
123 {
124 if ((bool)animeGroup)
125 {
126 animeGroup.alpha = 0f;
127 }
128 else if ((bool)uiText)
129 {
130 Color color = uiText.color;
131 color.a = 0f;
132 uiText.color = color;
133 }
134 }
135 }
136
137 public void Intro()
138 {
139 destTime = Time.realtimeSinceStartup + duration;
140 LateUpdate();
141 this.RebuildLayout();
142 if (!(intro == null))
143 {
145 }
146 }
147
148 private void LateUpdate()
149 {
150 if (!isOutro && isUseDuration && Time.realtimeSinceStartup > destTime)
151 {
152 Outro();
153 }
154 if ((bool)followTarget)
155 {
156 if (!followTarget.gameObject.activeInHierarchy && !lastPosition.HasValue)
157 {
158 Kill();
159 return;
160 }
161 if (!stopFollow && followTarget.gameObject.activeInHierarchy)
162 {
163 lastPosition = followTarget.position;
164 }
165 if (hasRect)
166 {
167 rect.position = Camera.main.WorldToScreenPoint(lastPosition ?? followTarget.position) + fixPos;
168 }
169 else
170 {
171 base.transform.position = (lastPosition ?? followTarget.position) + fixPos;
172 }
173 }
174 if (clamp)
175 {
177 }
178 }
179
180 private void ClampToScreen()
181 {
182 if (hasRect)
183 {
184 Vector3 zero = Vector3.zero;
185 Vector3 vector = (base.transform.parent as RectTransform).rect.min - rect.rect.min;
186 Vector3 vector2 = (base.transform.parent as RectTransform).rect.max - rect.rect.max;
187 zero.x = Mathf.Clamp(rect.localPosition.x, vector.x, vector2.x);
188 zero.y = Mathf.Clamp(rect.localPosition.y, vector.y, vector2.y);
189 rect.localPosition = zero;
190 }
191 else
192 {
193 Vector3 position = Camera.main.WorldToViewportPoint(base.transform.position);
194 position.x = Mathf.Clamp(position.x, 0.1f, 0.9f);
195 position.y = Mathf.Clamp(position.y, 0.1f, 0.9f);
196 base.transform.position = Camera.main.ViewportToWorldPoint(position);
197 }
198 }
199
200 public void ForceOutro()
201 {
202 if (!isOutro)
203 {
204 isOutro = true;
205 if ((bool)outroForce)
206 {
208 }
209 else
210 {
211 Kill();
212 }
213 }
214 }
215
216 public void Outro()
217 {
218 isOutro = true;
219 if (outro == null)
220 {
221 destY += 80f;
222 animeTarget.DOLocalMoveY(destY, 1.6f).SetEase(Ease.OutQuart).OnComplete(Kill);
223 }
224 else
225 {
227 }
228 }
229
230 public void Kill()
231 {
232 if (!isKilled)
233 {
234 base.transform.DOKill();
235 if ((bool)reciever)
236 {
237 reciever.Remove(this);
238 }
239 if (pooling)
240 {
241 stopFollow = false;
242 isOutro = false;
243 isKilled = false;
244 isUseDuration = true;
245 lastPosition = null;
246 destY = 0f;
247 }
248 else
249 {
250 UnityEngine.Object.Destroy(base.gameObject);
251 }
252 isKilled = true;
253 }
254 }
255
256 public void SetDuration(float duration)
257 {
258 this.duration = duration;
259 destTime = Time.realtimeSinceStartup + duration;
260 }
261}
Definition: Anime.cs:6
virtual Tween Play(Transform trans, UnityAction onComplete=null, float duration=-1f, float delay=0f)
Definition: Anime.cs:7
string text
Definition: BalloonData.cs:5
Anime outroForce
Definition: PopfabItem.cs:16
void ForceOutro()
Definition: PopfabItem.cs:200
void Set(BalloonData data)
Definition: PopfabItem.cs:91
bool screenSpace
Definition: PopfabItem.cs:35
bool stopFollow
Definition: PopfabItem.cs:41
void Outro()
Definition: PopfabItem.cs:216
bool isKilled
Definition: PopfabItem.cs:26
Popfab reciever
Definition: PopfabItem.cs:53
bool pooling
Definition: PopfabItem.cs:22
bool hasRect
Definition: PopfabItem.cs:71
ContentSizeFitter fitter
Definition: PopfabItem.cs:37
Vector3? lastPosition
Definition: PopfabItem.cs:65
void LateUpdate()
Definition: PopfabItem.cs:148
bool isOutro
Definition: PopfabItem.cs:59
Transform animeTarget
Definition: PopfabItem.cs:8
void Kill()
Definition: PopfabItem.cs:230
Anime outro
Definition: PopfabItem.cs:14
bool isUseDuration
Definition: PopfabItem.cs:68
void SetDuration(float duration)
Definition: PopfabItem.cs:256
CanvasGroup animeGroup
Definition: PopfabItem.cs:10
bool startTransparent
Definition: PopfabItem.cs:28
Text uiText
Definition: PopfabItem.cs:33
float destY
Definition: PopfabItem.cs:47
Transform followTarget
Definition: PopfabItem.cs:62
void Set(string text)
Definition: PopfabItem.cs:83
Anime intro
Definition: PopfabItem.cs:12
RectTransform rect
Definition: PopfabItem.cs:50
Anime loop
Definition: PopfabItem.cs:18
float destX
Definition: PopfabItem.cs:44
Vector3 fixPos
Definition: PopfabItem.cs:24
float duration
Definition: PopfabItem.cs:20
Image icon
Definition: PopfabItem.cs:39
void Intro()
Definition: PopfabItem.cs:137
bool clamp
Definition: PopfabItem.cs:30
void Init(Transform parent=null)
Definition: PopfabItem.cs:104
void ClampToScreen()
Definition: PopfabItem.cs:180
float destTime
Definition: PopfabItem.cs:56
void Awake()
Definition: PopfabItem.cs:73
Definition: Popfab.cs:6
void Remove(PopfabItem item)
Definition: Popfab.cs:70