This repository has been archived on 2025-03-20. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
mojo-kitchen-chaos/Assets/Scripts/UI/ProgressBarUI.cs

50 lines
1.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
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 componenet that implements IHasProgress!");
}
hasProgress.OnProgressChange += HasProgress_OnProgressChange;
barImage.fillAmount = 0f;
Hide();
}
private void HasProgress_OnProgressChange(object sender, IHasProgress.OnProgressChangeEventsArgs e)
{
barImage.fillAmount = e.progressNormalized;
if (e.progressNormalized == 0f || e.progressNormalized == 1f) {
Hide();
} else
{
Show();
}
}
private void Show()
{
gameObject.SetActive(true);
}
private void Hide()
{
gameObject.SetActive(false);
}
}