UI系统优化

This commit is contained in:
2026-05-25 11:54:37 +08:00
parent c7057db27d
commit 3c812cfb41
130 changed files with 4738 additions and 477 deletions

View File

@@ -1,6 +1,7 @@
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using TMPro;
using BaseGames.Core.Events;
@@ -11,15 +12,28 @@ namespace BaseGames.UI.Menus
[SerializeField] private TMP_Text _deathMessage;
[SerializeField] private Button _btnRespawn;
[Header("时序")]
[Tooltip("死亡画面出现前的缓冲延迟(秒)。调整此值可匹配死亡动画时长。")]
[SerializeField] private float _showDelay = 1.5f;
[Tooltip("死亡文字默认显示内容,会被本地化系统覆盖(如果已配置)。")]
[SerializeField] private string _defaultDeathText = "決死";
[Header("Event Channels")]
[SerializeField] private VoidEventChannelSO _onDeathScreenConfirmed;
private WaitForSecondsRealtime _showDelayWait;
private void Awake()
{
_showDelayWait = new WaitForSecondsRealtime(_showDelay);
}
private void OnEnable()
{
// 死亡界面由 UIManager 在游戏状态变为 Dead 时通过 SetActive(true) 激活。
// _onPlayerDied 事件此时已经触发完毕,订阅它不会收到回调。
// 直接在 OnEnable 启动延迟显示协程即可保证 1.5s 缓冲。
StartCoroutine(ShowAfterDelay(1.5f));
StartCoroutine(ShowAfterDelay(_showDelay));
}
private void OnDisable()
@@ -29,17 +43,22 @@ namespace BaseGames.UI.Menus
private IEnumerator ShowAfterDelay(float delay)
{
yield return new WaitForSeconds(delay);
yield return _showDelayWait;
Show();
}
private void Show()
{
if (_deathMessage != null) _deathMessage.text = _defaultDeathText;
if (_btnRespawn != null)
{
_btnRespawn.onClick.RemoveAllListeners();
_btnRespawn.onClick.AddListener(Confirm);
}
// 手柄导航:死亡界面显示后将焦点置于复活按钮
EventSystem.current?.SetSelectedGameObject(_btnRespawn?.gameObject);
}
private void Confirm()