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
|
||||
}
|
||||
}
|
||||
2
Assets/_Content/Scripts/UI/AmmoView.cs.meta
Normal file
2
Assets/_Content/Scripts/UI/AmmoView.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca9ade34ced9c264fad512c9408d61d8
|
||||
33
Assets/_Content/Scripts/UI/GameOverView.cs
Normal file
33
Assets/_Content/Scripts/UI/GameOverView.cs
Normal 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
|
||||
}
|
||||
}
|
||||
2
Assets/_Content/Scripts/UI/GameOverView.cs.meta
Normal file
2
Assets/_Content/Scripts/UI/GameOverView.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78d77256975d6d7499a20292c00b0649
|
||||
60
Assets/_Content/Scripts/UI/HealthView.cs
Normal file
60
Assets/_Content/Scripts/UI/HealthView.cs
Normal 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
|
||||
}
|
||||
}
|
||||
2
Assets/_Content/Scripts/UI/HealthView.cs.meta
Normal file
2
Assets/_Content/Scripts/UI/HealthView.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c96e24dd38a22b546a15f929ee0f0c91
|
||||
Reference in New Issue
Block a user