This commit is contained in:
2026-11-04 15:51:04 +01:00
parent d21f0c9b6c
commit cd65f702ae
111 changed files with 246848 additions and 1021 deletions

View File

@@ -4,56 +4,72 @@ 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;
}
/// <summary>
/// Displays the ammo of a launcher as "current / max".
/// </summary>
public class AmmoView : MonoBehaviour
{
[System.Serializable]
private struct References
{
public TMP_Text Label;
}
#region Fields
#region FIELDS
[SerializeField] private References _references;
[SerializeField] private References _references;
private ProjectileLauncher _launcher;
private ProjectileLauncher _launcher;
#endregion
#endregion
#region Unity Lifecycle
#region UNITY LIFECYCLES
private void OnDestroy()
{
if (_launcher != null)
_launcher.OnAmmoChange -= HandleAmmoChange;
}
void OnDestroy()
{
Unbind();
}
#endregion
#endregion
#region Public Methods
#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);
}
/// <summary>
/// Starts displaying the ammo of a launcher, instead of the previous one. Called by the UiManager.
/// </summary>
public void Bind(ProjectileLauncher launcher)
{
Unbind();
#endregion
_launcher = launcher;
#region Private Methods
if (!_launcher)
{
_references.Label.SetText("-");
return;
}
private void HandleAmmoChange(int current, int max)
{
_references.Label.SetText("{0} / {1}", current, max);
}
_launcher.OnAmmoChange += HandleAmmoChange;
HandleAmmoChange(_launcher.State.Ammo, _launcher.MaxAmmo);
}
#endregion
}
#endregion
#region PRIVATE METHODS
private void Unbind()
{
if (_launcher)
_launcher.OnAmmoChange -= HandleAmmoChange;
_launcher = null;
}
private void HandleAmmoChange(int current, int max)
{
_references.Label.SetText("{0} / {1}", current, max);
}
#endregion
}
}