-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeliveryPointUI.cs
46 lines (38 loc) · 1.23 KB
/
DeliveryPointUI.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
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
public class DeliveryPointUI : MonoBehaviour
{
[SerializeField] private float fadeOutTime;
[SerializeField] private float waitFadingTime;
private Image _image;
private RectTransform _fill;
private const int DecibelConverter = 100;
private void Awake()
{
_image = GetComponent<Image>();
_fill = GetComponent<RectTransform>();
}
/// <summary>
/// Sets the amount of the fill bar to the percentage of the items delivered.
/// </summary>
/// <param name="fillAmount">The percentage of the fill.</param>
/// <param name="isFull">Is the DeliveryPoint full</param>
public void SetFillAmount(float fillAmount, bool isFull)
{
var scale = new Vector3(fillAmount / DecibelConverter, _fill.localScale.y);
_fill.localScale = scale;
if (isFull) _image.color = Color.green;
ResetAlpha();
StartCoroutine(FadeOut());
}
private void ResetAlpha()
{
_image.CrossFadeAlpha(1,0,false);
}
private IEnumerator FadeOut()
{
yield return new WaitForSeconds(waitFadingTime);
_image.CrossFadeAlpha(0, fadeOutTime, false);
}
}