摄像机区域的架构改动
This commit is contained in:
51
Assets/_Game/Scripts/UI/Menus/DeathScreenController.cs
Normal file
51
Assets/_Game/Scripts/UI/Menus/DeathScreenController.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
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 _onDeathScreenConfirmed;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
// 死亡界面由 UIManager 在游戏状态变为 Dead 时通过 SetActive(true) 激活。
|
||||
// _onPlayerDied 事件此时已经触发完毕,订阅它不会收到回调。
|
||||
// 直接在 OnEnable 启动延迟显示协程即可保证 1.5s 缓冲。
|
||||
StartCoroutine(ShowAfterDelay(1.5f));
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
StopAllCoroutines();
|
||||
}
|
||||
|
||||
private IEnumerator ShowAfterDelay(float delay)
|
||||
{
|
||||
yield return new WaitForSeconds(delay);
|
||||
Show();
|
||||
}
|
||||
|
||||
private void Show()
|
||||
{
|
||||
if (_btnRespawn != null)
|
||||
{
|
||||
_btnRespawn.onClick.RemoveAllListeners();
|
||||
_btnRespawn.onClick.AddListener(Confirm);
|
||||
}
|
||||
}
|
||||
|
||||
private void Confirm()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
_onDeathScreenConfirmed?.Raise();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user