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

@@ -42,28 +42,24 @@ namespace BaseGames.UI
// ── Lifecycle ─────────────────────────────────────────────────────────
private void Awake()
{
ServiceLocator.RegisterIfAbsent<IInputIconService>(this);
_activeSet = _kbMouseSet;
}
private void OnEnable()
{
// OnEnable/OnDisable 对称注册:支持多场景加载时 GameObject 的启用/禁用周期
ServiceLocator.RegisterIfAbsent<IInputIconService>(this);
_onDeviceChanged?.Subscribe(HandleDeviceChanged).AddTo(_subs);
// 改键后 InputSystem 会广播 BoundControlsChanged
InputSystem.onActionChange += HandleActionChange;
}
private void OnDisable()
{
ServiceLocator.Unregister<IInputIconService>(this); // 仅注销自身ReferenceEquals 保护)
_subs.Clear();
InputSystem.onActionChange -= HandleActionChange;
}
private void OnDestroy()
{
ServiceLocator.Unregister<IInputIconService>(this);
}
// ── Event Handlers ────────────────────────────────────────────────────
private void HandleDeviceChanged(InputDeviceType deviceType)
@@ -94,6 +90,12 @@ namespace BaseGames.UI
return _activeSet.GetIcon(path);
}
public Sprite GetPathIcon(string bindingPath)
{
if (_activeSet == null || string.IsNullOrEmpty(bindingPath)) return null;
return _activeSet.GetIcon(bindingPath);
}
public string GetActionEffectivePath(string actionName)
{
if (_inputReader == null) return null;