多轮审查和修复

This commit is contained in:
2026-05-12 15:34:08 +08:00
parent f55d2a57c3
commit ebbbb7332e
805 changed files with 838724 additions and 1905 deletions

View File

@@ -0,0 +1,68 @@
using UnityEngine;
using UnityEngine.UI;
using BaseGames.Core.Events;
namespace BaseGames.UI
{
/// <summary>
/// 输入设备图标切换器(架构 10_UIModule §12
/// 订阅 EVT_InputDeviceChangedBoolEventChannelSOtrue = 手柄false = 键鼠),
/// 切换后广播给场景内所有 InputIconImage 组件。
/// 通常挂在 UIRoot 或 UIManager 同一 GameObject 上。
/// </summary>
public class InputDeviceIconSwitcher : MonoBehaviour
{
[SerializeField] private InputDeviceIconSetSO _kbIconSet;
[SerializeField] private InputDeviceIconSetSO _padIconSet;
[Header("Event Channel")]
[SerializeField] private BoolEventChannelSO _onDeviceChanged; // EVT_InputDeviceChanged
public static InputDeviceIconSetSO Current { get; private set; }
private readonly CompositeDisposable _subs = new();
private void Awake() { Current = _kbIconSet; }
private void OnEnable() => _onDeviceChanged?.Subscribe(SwitchIconSet).AddTo(_subs);
private void OnDisable() => _subs.Clear();
private void SwitchIconSet(bool isGamepad)
{
Current = isGamepad ? _padIconSet : _kbIconSet;
// 通知所有图标 Image 刷新
foreach (var img in GetComponentsInChildren<InputIconImage>(includeInactive: true))
img.Refresh();
}
}
// ─────────────────────────────────────────────────────────────────────────
/// <summary>
/// 单个按键图标 Image 组件。
/// 记录 bindingPath由 InputDeviceIconSwitcher 切换时自动刷新。
/// </summary>
[RequireComponent(typeof(Image))]
public class InputIconImage : MonoBehaviour
{
[Tooltip("InputSystem 绑定路径,如 <Keyboard>/space 或 <Gamepad>/buttonSouth")]
[SerializeField] private string _bindingPath;
private Image _image;
private void Awake() => _image = GetComponent<Image>();
private void Start() => Refresh();
public void Refresh()
{
if (_image == null || string.IsNullOrEmpty(_bindingPath)) return;
var set = InputDeviceIconSwitcher.Current;
if (set == null) return;
var sprite = set.GetIcon(_bindingPath);
if (sprite != null)
{
_image.sprite = sprite;
_image.enabled = true;
}
}
}
}