35 lines
912 B
C#
35 lines
912 B
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class ProgressBarUI : MonoBehaviour {
|
|
[SerializeField] private GameObject hasProgressGameObject;
|
|
[SerializeField] private Image barImage;
|
|
|
|
private IHasProgress hasProgress;
|
|
|
|
private void Start() {
|
|
hasProgress = hasProgressGameObject.GetComponent<IHasProgress>();
|
|
if (hasProgress == null)
|
|
Debug.LogError($"Game Object {hasProgressGameObject} does not have a component that implements IHasProgress!");
|
|
else
|
|
hasProgress.OnProgressChanged += HasProgress_OnProgressChanged;
|
|
barImage.fillAmount = 0f;
|
|
Hide();
|
|
}
|
|
|
|
private void HasProgress_OnProgressChanged(object sender, IHasProgress.ProgressChangedEventArgs e) {
|
|
barImage.fillAmount = e.ProgressNormalized;
|
|
if (e.ProgressNormalized is 0f or 1f)
|
|
Hide();
|
|
else
|
|
Show();
|
|
}
|
|
|
|
private void Show() {
|
|
gameObject.SetActive(true);
|
|
}
|
|
|
|
private void Hide() {
|
|
gameObject.SetActive(false);
|
|
}
|
|
} |