Elin Decompiled Documentation EA 23.130 Nightly
Loading...
Searching...
No Matches
LayerProgress.cs
Go to the documentation of this file.
1using System;
2using System.Threading;
3using Cysharp.Threading.Tasks;
4using DG.Tweening;
5using UnityEngine;
6using UnityEngine.UI;
7
8public class LayerProgress : ELayer
9{
10 public static bool completed;
11
12 public static bool isActive;
13
14 public static float progress;
15
16 public float speed;
17
18 public float minTime;
19
20 public float endTime;
21
22 public float minProgress;
23
24 public Slider bar;
25
26 public Text text;
27
28 public Action onComplete;
29
30 public Func<bool> funcComplete;
31
32 public UniTask<bool> unitask;
33
34 public Action onCancel;
35
36 public bool useUnitask;
37
38 public CanvasGroup cg;
39
40 private float value;
41
42 public void Init(string hint)
43 {
44 text.text = hint;
45 completed = false;
46 isActive = true;
47 progress = (value = 0f);
48 cg.alpha = 0f;
49 cg.DOFade(1f, 0.1f).SetEase(Ease.InCubic).SetDelay(0.2f);
50 }
51
52 public void Update()
53 {
54 if (onCancel != null && Input.GetKeyDown(KeyCode.Escape))
55 {
56 isActive = false;
57 Close();
58 onCancel();
59 return;
60 }
61 minTime -= Time.deltaTime;
62 if (progress < 0.9f)
63 {
64 progress += minProgress * Time.deltaTime;
65 }
66 value = Mathf.Lerp(value, progress, Time.deltaTime * speed);
67 if (useUnitask && unitask.Status == UniTaskStatus.Succeeded)
68 {
69 completed = true;
70 }
71 bar.value = Mathf.Clamp(value, 0f, 1f);
72 if (!completed || !(minTime < 0f))
73 {
74 return;
75 }
76 progress = 1f;
77 speed *= 5f;
78 endTime -= Time.deltaTime;
79 if (!(endTime > 0f))
80 {
81 isActive = false;
82 Close();
83 if (onComplete != null)
84 {
85 onComplete();
86 }
87 }
88 }
89
90 public static LayerProgress StartAsync(string text, UniTask<bool> task, Action onCancel = null)
91 {
92 LayerProgress layerProgress = ELayer.ui.AddLayer<LayerProgress>();
93 layerProgress.Init(text);
94 layerProgress.useUnitask = true;
95 layerProgress.unitask = task;
96 layerProgress.onCancel = onCancel;
97 return layerProgress;
98 }
99
100 public static LayerProgress Start(string text, Action onComplete = null)
101 {
102 LayerProgress layerProgress = ELayer.ui.AddLayer<LayerProgress>();
103 layerProgress.Init(text);
104 layerProgress.onComplete = onComplete;
105 return layerProgress;
106 }
107
108 public static void Start(string text, Action thread, Action onComplete)
109 {
111 {
112 thread();
113 onComplete();
114 return;
115 }
116 LayerProgress layerProgress = ELayer.ui.AddLayer<LayerProgress>();
117 layerProgress.Init(text);
118 layerProgress.onComplete = onComplete;
119 ThreadPool.QueueUserWorkItem(delegate
120 {
121 thread();
122 completed = true;
123 });
124 }
125}
@ hint
bool dontUseThread
Definition: CoreDebug.cs:121
CoreDebug debug
Definition: Core.cs:31
Definition: ELayer.cs:4
static Core core
Definition: ELayer.cs:7
static UI ui
Definition: ELayer.cs:21
static void Start(string text, Action thread, Action onComplete)
static bool isActive
Action onComplete
static bool completed
static LayerProgress Start(string text, Action onComplete=null)
static float progress
void Init(string hint)
CanvasGroup cg
Func< bool > funcComplete
static LayerProgress StartAsync(string text, UniTask< bool > task, Action onCancel=null)
UniTask< bool > unitask
virtual void Close()
Definition: Layer.cs:463