AlicizaX/Client/Assets/InputGlyph/InputGlyphImage.cs
陈思海 5862fb2af1 add
1.新增手柄相关适配
2.新增设备重映射绑定
3.新增设备映射图标更新
2025-12-09 20:31:44 +08:00

41 lines
1.2 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.InputSystem;
using AlicizaX.InputGlyph;
[RequireComponent(typeof(Image))]
public class InputGlyphImage : MonoBehaviour
{
[SerializeField] private InputActionReference actionReference;
private Image targetImage;
[SerializeField] private bool hideIfMissing = true;
void OnEnable()
{
if (targetImage == null) targetImage = GetComponent<Image>();
InputDeviceWatcher.OnDeviceChanged += OnDeviceChanged;
UpdatePrompt();
}
void OnDisable()
{
InputDeviceWatcher.OnDeviceChanged -= OnDeviceChanged;
}
void OnDeviceChanged(InputDeviceWatcher.InputDeviceCategory cat)
{
UpdatePrompt();
}
void UpdatePrompt()
{
if (actionReference == null || actionReference.action == null || targetImage == null) return;
InputDeviceWatcher.InputDeviceCategory deviceCategory = InputDeviceWatcher.CurrentCategory;
string path = GlyphService.GetBindingControlPath(actionReference);
if (GlyphService.TryGetUISpriteForActionPath(path, deviceCategory, out Sprite sprite))
{
targetImage.sprite = sprite;
}
}
}