feat: Player
This commit is contained in:
59
Assets/_Content/Scripts/UI/AmmoView.cs
Normal file
59
Assets/_Content/Scripts/UI/AmmoView.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user