49 lines
1.2 KiB
C#
49 lines
1.2 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
/// <summary>
|
|
/// HUD element which displays a ships remaining boost capacity.
|
|
/// </summary>
|
|
public class BoostCapacityUI : MonoBehaviour
|
|
{
|
|
public Color goodColor = Color.green;
|
|
public Color criticalColor = Color.red;
|
|
[SerializeField] private int playerNumber = 0;
|
|
[SerializeField] private Image fillImage;
|
|
[SerializeField] private TextMeshProUGUI hint;
|
|
private float minBoostRatio = 0.3f;
|
|
|
|
/// <summary>
|
|
/// Ratio of capacity to max capacity under which the
|
|
/// boost capacity is considered critically low.
|
|
/// </summary>
|
|
/// <param name="minBoostRatio"></param>
|
|
public void SetMinBoostRatio(float minBoostRatio)
|
|
{
|
|
this.minBoostRatio = minBoostRatio;
|
|
}
|
|
|
|
public void SetPlayerName(Player p)
|
|
{
|
|
hint.SetText($"{p.character.shipName} \n {p.playerName}");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Updates the color and fill of the capacity meter.
|
|
/// </summary>
|
|
/// <param name="fill">Fill percentage</param>
|
|
public void UpdateFill(float fill)
|
|
{
|
|
fillImage.fillAmount = fill;
|
|
if (fillImage.fillAmount <= minBoostRatio)
|
|
{
|
|
fillImage.color = criticalColor;
|
|
}
|
|
else
|
|
{
|
|
fillImage.color = goodColor;
|
|
}
|
|
}
|
|
}
|