60 lines
1.0 KiB
C#
60 lines
1.0 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
using Arena.Combat;
|
|
|
|
namespace Arena.UI
|
|
{
|
|
/// <summary>
|
|
/// Displays the ammo of a launcher as "current / max".
|
|
/// </summary>
|
|
public class AmmoView : MonoBehaviour
|
|
{
|
|
[System.Serializable]
|
|
public struct References
|
|
{
|
|
public TMP_Text Label;
|
|
}
|
|
|
|
#region Fields
|
|
|
|
[SerializeField] private References _references;
|
|
|
|
private ProjectileLauncher _launcher;
|
|
|
|
#endregion
|
|
|
|
#region Unity Lifecycle
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (_launcher != null)
|
|
_launcher.OnAmmoChange -= HandleAmmoChange;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Starts displaying the ammo of a launcher. Called by the UiManager.
|
|
/// </summary>
|
|
public void Bind(ProjectileLauncher launcher)
|
|
{
|
|
_launcher = launcher;
|
|
_launcher.OnAmmoChange += HandleAmmoChange;
|
|
HandleAmmoChange(_launcher.State.Ammo, _launcher.MaxAmmo);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Private Methods
|
|
|
|
private void HandleAmmoChange(int current, int max)
|
|
{
|
|
_references.Label.SetText("{0} / {1}", current, max);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|