chore: initial commit
This commit is contained in:
52
Assets/Scripts/UI/Menus/DeathScreenController.cs
Normal file
52
Assets/Scripts/UI/Menus/DeathScreenController.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using BaseGames.Core.Events;
|
||||
|
||||
namespace BaseGames.UI.Menus
|
||||
{
|
||||
public class DeathScreenController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TMP_Text _deathMessage;
|
||||
[SerializeField] private Button _btnRespawn;
|
||||
|
||||
[Header("Event Channels")]
|
||||
[SerializeField] private VoidEventChannelSO _onPlayerDied;
|
||||
[SerializeField] private VoidEventChannelSO _onDeathScreenConfirmed;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (_onPlayerDied != null) _onPlayerDied.OnEventRaised += OnPlayerDied;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (_onPlayerDied != null) _onPlayerDied.OnEventRaised -= OnPlayerDied;
|
||||
}
|
||||
|
||||
private void OnPlayerDied() => StartCoroutine(ShowAfterDelay(1.5f));
|
||||
|
||||
private IEnumerator ShowAfterDelay(float delay)
|
||||
{
|
||||
yield return new WaitForSeconds(delay);
|
||||
Show();
|
||||
}
|
||||
|
||||
private void Show()
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
if (_btnRespawn != null)
|
||||
{
|
||||
_btnRespawn.onClick.RemoveAllListeners();
|
||||
_btnRespawn.onClick.AddListener(Confirm);
|
||||
}
|
||||
}
|
||||
|
||||
private void Confirm()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
_onDeathScreenConfirmed?.Raise();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/Menus/DeathScreenController.cs.meta
Normal file
11
Assets/Scripts/UI/Menus/DeathScreenController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b6773e585eac299448529521e4b090c7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user