36 lines
1.4 KiB
C#
36 lines
1.4 KiB
C#
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using BaseGames.Core;
|
||
using BaseGames.Core.Events;
|
||
|
||
namespace BaseGames.UI
|
||
{
|
||
/// <summary>
|
||
/// 输入设备图标切换器。
|
||
/// 订阅 InputDeviceTypeEventChannelSO,在设备切换时通知场景内所有 InputIconImage 刷新。
|
||
///
|
||
/// ⚠️ 旧版只支持 KB / 手柄二值切换;新版支持 KeyboardMouse / Xbox / PlayStation / Switch。
|
||
/// 通常挂在 UIRoot 上,与 InputDeviceDetector 配合使用。
|
||
/// </summary>
|
||
public class InputDeviceIconSwitcher : MonoBehaviour
|
||
{
|
||
[Header("Event Channel")]
|
||
[Tooltip("由 InputDeviceDetector 广播的设备类型事件")]
|
||
[SerializeField] private InputDeviceTypeEventChannelSO _onDeviceChanged;
|
||
|
||
private readonly CompositeDisposable _subs = new();
|
||
|
||
private void OnEnable() => _onDeviceChanged?.Subscribe(OnDeviceChanged).AddTo(_subs);
|
||
private void OnDisable() => _subs.Clear();
|
||
|
||
private void OnDeviceChanged(InputDeviceType _)
|
||
{
|
||
// InputIconImage 已通过订阅 IInputIconService.OnIconSetChanged 自主刷新,
|
||
// 无需重复调用 RefreshAll()——否则每次设备切换每个 InputIconImage 会执行两次 Refresh。
|
||
// 此处保留供将来添加设备切换时的其他 UI 响应(提示动画、音效反馈等)。
|
||
}
|
||
}
|
||
}
|
||
|