feat: Player

This commit is contained in:
2026-10-07 15:46:51 +02:00
parent 074eb51084
commit d21f0c9b6c
45 changed files with 1801 additions and 74 deletions

View 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
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: ca9ade34ced9c264fad512c9408d61d8

View File

@@ -0,0 +1,33 @@
using UnityEngine;
using UnityEngine.SceneManagement;
namespace Arena.UI
{
/// <summary>
/// Game over screen. Its Restart button reloads the scene.
/// </summary>
public class GameOverView : MonoBehaviour
{
#region Public Methods
public void Show()
{
gameObject.SetActive(true);
}
public void Hide()
{
gameObject.SetActive(false);
}
/// <summary>
/// Called by the Restart button (OnClick in the Inspector).
/// </summary>
public void Restart()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
#endregion
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 78d77256975d6d7499a20292c00b0649

View File

@@ -0,0 +1,60 @@
using TMPro;
using UnityEngine;
using Arena.Combat;
namespace Arena.UI
{
/// <summary>
/// Displays a Health as "current / max".
/// </summary>
public class HealthView : MonoBehaviour
{
[System.Serializable]
public struct References
{
public TMP_Text Label;
}
#region Fields
[SerializeField] private References _references;
private Health _health;
#endregion
#region Unity Lifecycle
private void OnDestroy()
{
// Every subscription has its unsubscription
if (_health != null)
_health.OnChange -= HandleHealthChange;
}
#endregion
#region Public Methods
/// <summary>
/// Starts displaying a Health. Called by the UiManager.
/// </summary>
public void Bind(Health health)
{
_health = health;
_health.OnChange += HandleHealthChange;
HandleHealthChange(_health.Current, _health.Max);
}
#endregion
#region Private Methods
private void HandleHealthChange(int current, int max)
{
_references.Label.SetText("{0} / {1}", current, max);
}
#endregion
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: c96e24dd38a22b546a15f929ee0f0c91