#if INPUTSYSTEM_SUPPORT using System.Linq; using AlicizaX.UI.Runtime; using UnityEngine; namespace UnityEngine.UI { public class HotkeyBindComponent : MonoBehaviour { private UIHolderObjectBase _holderObjectBase; private void Awake() { _holderObjectBase = GetComponent(); _holderObjectBase.OnWindowBeforeShowEvent += BindHotKeys; _holderObjectBase.OnWindowBeforeClosedEvent += UnBindHotKeys; } private void OnDestroy() { if (_holderObjectBase != null) { _holderObjectBase.OnWindowBeforeShowEvent -= BindHotKeys; _holderObjectBase.OnWindowBeforeClosedEvent -= UnBindHotKeys; } } [SerializeField] private Component[] hotButtons; internal void BindHotKeys() { if (hotButtons == null) return; for (int i = 0; i < hotButtons.Length; i++) { if (hotButtons[i] is IHotkeyTrigger trigger) { trigger.BindHotKey(); } } } #if UNITY_EDITOR [ContextMenu("Bind HotKeys")] private void CollectUXHotkeys() { var found = gameObject .GetComponentsInChildren(true) .OfType() .Where(t => t.HotkeyAction != null) .Select(t => t as Component) .ToArray(); hotButtons = found; } private void OnValidate() { if (_holderObjectBase == null) { _holderObjectBase = gameObject.GetComponent(); CollectUXHotkeys(); } } #endif internal void UnBindHotKeys() { if (hotButtons == null) return; for (int i = 0; i < hotButtons.Length; i++) { if (hotButtons[i] is IHotkeyTrigger trigger) { trigger.UnBindHotKey(); } } } } } #endif