UI系统优化
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user