-
Notifications
You must be signed in to change notification settings - Fork 241
/
ProgressBarView.cs
99 lines (84 loc) · 2.44 KB
/
ProgressBarView.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
namespace PlayFab.UI
{
using System;
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(Slider))]
public class ProgressBarView : MonoBehaviour
{
public Slider Slider;
public Text Label;
public TweenTypes TweenType;
public AnimationCurve Curve;
private bool _isAnimating = false;
private float _start;
private float _end;
private Action _callback;
private float _t;
public void Awake()
{
if(Slider == null)
{
Slider = GetComponent<Slider>();
}
}
public void UpdateProgress(float progress)
{
Slider.value = progress;
}
public void AnimateProgress(float start, float end)
{
_t = 0f;
_start = start;
_end = end;
_isAnimating = true;
}
public void AnimateProgress(float start, float end, Action callback)
{
_callback = callback;
AnimateProgress(start, end);
}
public void UpdateLabel(string label)
{
Label.gameObject.SetActive(true);
Label.text = label;
}
// Update is called once per frame
void Update()
{
if (_isAnimating)
{
_t += Time.deltaTime;
switch (TweenType)
{
case TweenTypes.Linear:
if (Slider.value < 1)
{
Slider.value = Tween.Linear(_start, _end, _t);
}
break;
case TweenTypes.EaseIn:
if(Slider.value < 1)
{
Slider.value = Tween.EaseIn(_start, _end, _t);
}
break;
case TweenTypes.Curve:
if (Slider.value < 1)
{
Slider.value = Tween.Curve(_start, _end, Curve, _t);
}
break;
}
if(Slider.value >= 1)
{
if(_callback != null)
{
_isAnimating = false;
_callback();
}
}
}
}
}
}