using System; using System.Collections.Generic; using AlicizaX.UI.Runtime; using Sirenix.OdinInspector; using UnityEngine; namespace AlicizaX.UI.Extension.UXComponent.Hotkey { public class HotkeyBindComponent : MonoBehaviour { private UIHolderObjectBase _holderObjectBase; private void Awake() { _holderObjectBase = GetComponent(); _holderObjectBase.OnWindowShowEvent += BindHotKeys; _holderObjectBase.OnWindowClosedEvent += UnBindHotKeys; } private void OnDestroy() { _holderObjectBase.OnWindowShowEvent -= BindHotKeys; _holderObjectBase.OnWindowClosedEvent -= UnBindHotKeys; } #if UNITY_EDITOR [InlineButton("SetHotKeyButtons")] #endif [SerializeField] [HideLabel] private UXButton[] hotButtons; #if UNITY_EDITOR private void SetHotKeyButtons() { var btns = transform.GetComponentsInChildren(true); var hotBtnList = new List(); for (int i = 0; i < btns.Length; i++) { if (btns[i].HasHotKeyRefrenced()) { hotBtnList.Add(btns[i]); } } hotButtons = hotBtnList.ToArray(); } #endif internal void BindHotKeys() { for (int i = 0; i < hotButtons.Length; i++) { hotButtons[i].BindHotKey(); } } internal void UnBindHotKeys() { for (int i = 0; i < hotButtons.Length; i++) { hotButtons[i].UnBindHotKey(); } } } }