2026-03-17 20:02:47 +08:00
|
|
|
|
using UnityEngine;
|
2026-03-09 20:38:15 +08:00
|
|
|
|
using UnityEngine.InputSystem;
|
2026-03-17 20:02:47 +08:00
|
|
|
|
using UnityEngine.UI;
|
2026-03-09 20:38:15 +08:00
|
|
|
|
|
|
|
|
|
|
[RequireComponent(typeof(UXButton))]
|
2026-03-17 20:02:47 +08:00
|
|
|
|
public sealed class InputGlyphUXButton : InputGlyphBehaviourBase
|
2026-03-09 20:38:15 +08:00
|
|
|
|
{
|
|
|
|
|
|
[SerializeField] private UXButton button;
|
|
|
|
|
|
[SerializeField] private Image targetImage;
|
2026-03-17 20:02:47 +08:00
|
|
|
|
|
2026-03-09 20:38:15 +08:00
|
|
|
|
private Sprite _cachedSprite;
|
|
|
|
|
|
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
|
private void OnValidate()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (button == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
button = GetComponent<UXButton>();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2026-03-17 20:02:47 +08:00
|
|
|
|
protected override void OnEnable()
|
2026-03-09 20:38:15 +08:00
|
|
|
|
{
|
2026-03-17 20:02:47 +08:00
|
|
|
|
if (button == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
button = GetComponent<UXButton>();
|
|
|
|
|
|
}
|
2026-03-09 20:38:15 +08:00
|
|
|
|
|
2026-03-17 20:02:47 +08:00
|
|
|
|
if (targetImage == null)
|
2026-03-09 20:38:15 +08:00
|
|
|
|
{
|
2026-03-17 20:02:47 +08:00
|
|
|
|
targetImage = GetComponent<Image>();
|
2026-03-09 20:38:15 +08:00
|
|
|
|
}
|
2026-03-17 20:02:47 +08:00
|
|
|
|
|
|
|
|
|
|
base.OnEnable();
|
2026-03-09 20:38:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-17 20:02:47 +08:00
|
|
|
|
protected override void RefreshGlyph()
|
2026-03-09 20:38:15 +08:00
|
|
|
|
{
|
2026-03-17 20:02:47 +08:00
|
|
|
|
InputActionReference actionReference = button != null ? button.HotKeyRefrence : null;
|
|
|
|
|
|
if (actionReference == null || actionReference.action == null || targetImage == null)
|
2026-03-09 20:38:15 +08:00
|
|
|
|
{
|
2026-03-17 20:02:47 +08:00
|
|
|
|
if (targetImage != null && _cachedSprite != null)
|
2026-03-09 20:38:15 +08:00
|
|
|
|
{
|
2026-03-17 20:02:47 +08:00
|
|
|
|
_cachedSprite = null;
|
|
|
|
|
|
targetImage.sprite = null;
|
2026-03-09 20:38:15 +08:00
|
|
|
|
}
|
2026-03-17 20:02:47 +08:00
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool hasSprite = GlyphService.TryGetUISpriteForActionPath(actionReference, string.Empty, CurrentCategory, out Sprite sprite);
|
|
|
|
|
|
if (!hasSprite)
|
|
|
|
|
|
{
|
|
|
|
|
|
sprite = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (_cachedSprite != sprite)
|
|
|
|
|
|
{
|
|
|
|
|
|
_cachedSprite = sprite;
|
|
|
|
|
|
targetImage.sprite = sprite;
|
2026-03-09 20:38:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|