AlicizaX/Client/Assets/InputGlyph/ActionPromptImage.cs

48 lines
2.5 KiB
C#
Raw Normal View History

2025-12-05 19:04:53 +08:00
// using UnityEngine;
// using UnityEngine.UI;
// using UnityEngine.InputSystem;
// using InputGlyphsFramework;
// using DeviceType = InputGlyphsFramework.DeviceType;
//
// [RequireComponent(typeof(RectTransform))]
// public class ActionPromptImage : MonoBehaviour
// {
// public InputActionReference actionReference;
// public int bindingIndex = 0;
// public Image targetImage;
// public bool hideIfMissing = true;
// Sprite lastSprite;
//
// void OnEnable()
// {
// if (targetImage == null) targetImage = GetComponentInChildren<Image>();
// if (InputService.Instance != null) InputService.Instance.OnBindingChanged += OnBindingChanged;
// InputDeviceWatcher.OnDeviceChanged += OnDeviceChanged;
// UpdatePrompt();
// }
// void OnDisable()
// {
// if (InputService.Instance != null) InputService.Instance.OnBindingChanged -= OnBindingChanged;
// InputDeviceWatcher.OnDeviceChanged -= OnDeviceChanged;
// }
// void OnBindingChanged(UnityEngine.InputSystem.InputAction action, int idx) { if (actionReference != null && actionReference.action == action) UpdatePrompt(); }
// void OnDeviceChanged(InputDeviceWatcher.InputDeviceCategory cat) { UpdatePrompt(); }
//
// void UpdatePrompt()
// {
// if (actionReference == null || actionReference.action == null || targetImage == null) return;
// var action = actionReference.action;
// int best = BindingGlyphHelper.FindBestBindingIndexForDevice(action);
// if (best >= 0) bindingIndex = best;
// string path = InputService.GetBindingControlPath(action, bindingIndex);
// var device = MapDevice(InputDeviceWatcher.CurrentCategory);
// if (GlyphService.Instance != null && GlyphService.Instance.TryGetUISpriteForActionPath(path, device, out Sprite s))
// {
// if (lastSprite != s) { targetImage.sprite = s; targetImage.enabled = true; lastSprite = s; }
// return;
// }
// lastSprite = null; if (hideIfMissing) targetImage.enabled = false; else targetImage.sprite = null;
// }
// static DeviceType MapDevice(InputDeviceWatcher.InputDeviceCategory cat) { switch (cat) { case InputDeviceWatcher.InputDeviceCategory.Xbox: return DeviceType.Xbox; case InputDeviceWatcher.InputDeviceCategory.PlayStation: return DeviceType.PlayStation; case InputDeviceWatcher.InputDeviceCategory.Other: return DeviceType.Other; default: return DeviceType.Keyboard; } }
// }