com.alicizax.unity.ui.exten.../Runtime/UXComponent/Hotkey/HotkeyBindComponent.cs
2025-12-10 11:11:59 +08:00

54 lines
1.3 KiB
C#

#if INPUTSYSTEM_SUPPORT
using AlicizaX.UI.Runtime;
using UnityEngine;
namespace AlicizaX.UI
{
// [DisallowMultipleComponent]
public class HotkeyBindComponent : MonoBehaviour
{
private UIHolderObjectBase _holderObjectBase;
private void Awake()
{
_holderObjectBase = GetComponent<UIHolderObjectBase>();
_holderObjectBase.OnWindowShowEvent += BindHotKeys;
_holderObjectBase.OnWindowClosedEvent += UnBindHotKeys;
}
private void OnDestroy()
{
_holderObjectBase.OnWindowShowEvent -= BindHotKeys;
_holderObjectBase.OnWindowClosedEvent -= UnBindHotKeys;
}
[SerializeField] private UXHotkeyButton[] hotButtons;
internal void BindHotKeys()
{
for (int i = 0; i < hotButtons.Length; i++)
{
hotButtons[i].BindHotKey();
}
}
#if UNITY_EDITOR
[ContextMenu("Bind HotKeys")]
private void CollectUXHotkeys()
{
hotButtons = gameObject.GetComponentsInChildren<UXHotkeyButton>(true);
}
#endif
internal void UnBindHotKeys()
{
for (int i = 0; i < hotButtons.Length; i++)
{
hotButtons[i].UnBindHotKey();
}
}
}
}
#endif