UI系统组件
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
using BaseGames.Core;
|
||||
using BaseGames.Core.Assets;
|
||||
using BaseGames.Core.Events;
|
||||
|
||||
@@ -10,9 +8,9 @@ namespace BaseGames.UI
|
||||
/// <summary>
|
||||
/// 暂停菜单控制器(架构 10_UIModule §5)。
|
||||
/// 挂载在 Canvas_Menu → PauseMenuPanel GameObject 上。
|
||||
/// 按钮绑定在 Awake 中完成;由 UIManager 负责面板开关。
|
||||
/// 按钮绑定在 Awake 中完成;生命周期 / 焦点由 <see cref="UIPanelBase"/> 统一处理。
|
||||
/// </summary>
|
||||
public class PauseMenuController : MonoBehaviour, IFocusable
|
||||
public class PauseMenuController : UIPanelBase
|
||||
{
|
||||
// UIManager 通过 ServiceLocator 解析,开启时自动获取,无需 Inspector 直接绑定具体类型
|
||||
private IUIManager _uiManager;
|
||||
@@ -35,18 +33,13 @@ namespace BaseGames.UI
|
||||
_btnQuit?.onClick.AddListener(Application.Quit);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
// 暂停面板由 UIManager 开启,此时 ServiceLocator 已就绪
|
||||
_uiManager = ServiceLocator.GetOrDefault<IUIManager>();
|
||||
// 手柄导航:打开时将焦点置于第一个按钮
|
||||
EventSystem.current?.SetSelectedGameObject(_btnResume?.gameObject);
|
||||
}
|
||||
// 暂停面板由 UIManager 开启,此时 ServiceLocator 已就绪
|
||||
protected override void OnPanelOpen() => _uiManager = GetService<IUIManager>();
|
||||
protected override void OnPanelClose() => _uiManager = null;
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
_uiManager = null;
|
||||
}
|
||||
/// <summary>默认焦点 / 焦点恢复回到"继续"按钮(基类 FocusFirst 调用)。</summary>
|
||||
protected override GameObject ResolveFirstSelected()
|
||||
=> _btnResume != null ? _btnResume.gameObject : null;
|
||||
|
||||
// ── 按钮回调 ──────────────────────────────────────────────────────────
|
||||
|
||||
@@ -71,11 +64,5 @@ namespace BaseGames.UI
|
||||
ShowLoadingScreen = false,
|
||||
});
|
||||
}
|
||||
|
||||
// ── IFocusable ────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>面板恢复为栈顶时(关闭子面板后)自动移回第一个按鈕。</summary>
|
||||
public void OnFocusRestored()
|
||||
=> EventSystem.current?.SetSelectedGameObject(_btnResume?.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user