UI 系统

This commit is contained in:
2026-06-08 11:26:17 +08:00
parent 1897658a00
commit b582317692
94 changed files with 33540 additions and 3726 deletions

View File

@@ -0,0 +1,43 @@
using UnityEngine;
using BaseGames.Input;
namespace BaseGames.UI
{
/// <summary>
/// 挂在"游戏内全屏菜单"根节点(如 InventoryHubRoot
/// 打开OnEnable时冻结游戏Time.timeScale=0并切到 UI 输入关闭OnDisable时恢复时间并切回 Gameplay 输入。
///
/// 解决的 bug游戏内菜单统一背包屏打开时本不改 GameState导致 Gameplay 输入仍激活、
/// 按 Esc 触发的是"暂停"而非"关闭菜单",且关闭后状态错乱使 Esc 不再暂停。
/// 切到 UI 输入后:菜单内 Esc=关闭UINavigator Cancel关闭后 Esc=暂停Gameplay
/// 同时冻结时间符合"打开背包暂停游戏"的常规手感。
///
/// 仅作用于本菜单的开/关与暂停菜单PausedState的真实暂停相互独立、互不冲突。
/// </summary>
[DisallowMultipleComponent]
public class MenuPauseScope : MonoBehaviour
{
[SerializeField] private InputReaderSO _inputReader;
[Tooltip("打开时是否冻结游戏时间Time.timeScale=0。菜单动画须用 unscaledDeltaTime。")]
[SerializeField] private bool _freezeTime = true;
private float _prevTimeScale = 1f;
private void OnEnable()
{
if (_freezeTime)
{
_prevTimeScale = Time.timeScale;
Time.timeScale = 0f;
}
_inputReader?.EnableUIInput();
}
private void OnDisable()
{
if (_freezeTime)
Time.timeScale = _prevTimeScale; // 恢复打开前的时间倍率(若打开前已是 0 则维持暂停,正确)
_inputReader?.EnableGameplayInput();
}
}
}