diff --git a/Editor/UX/Hotkey/HotkeyBindComponentInspector.cs b/Editor/UX/Hotkey/HotkeyBindComponentInspector.cs index 4417830..8be68b4 100644 --- a/Editor/UX/Hotkey/HotkeyBindComponentInspector.cs +++ b/Editor/UX/Hotkey/HotkeyBindComponentInspector.cs @@ -2,14 +2,15 @@ using System.Collections.Generic; using System.Reflection; using AlicizaX.Editor; +using AlicizaX.UI; using AlicizaX.UI.Runtime; using UnityEditor; using UnityEngine; -namespace AlicizaX.UI +namespace AlicizaX.UI111 { [CustomEditor(typeof(HotkeyBindComponent))] - public class HotkeyBindComponentInspector : GameFrameworkInspector + public class HotkeyBindComponentInspector : UnityEditor.Editor { private SerializedProperty hotButtonsProp; private HotkeyBindComponent _target; @@ -24,7 +25,7 @@ namespace AlicizaX.UI { serializedObject.Update(); - // 🔸 检查是否缺少 UIHolderObjectBase + var holder = _target.GetComponent(); if (holder == null) { @@ -98,9 +99,11 @@ namespace AlicizaX.UI .GetField("hotButtons", BindingFlags.NonPublic | BindingFlags.Instance) ?.SetValue(_target, valiedHotkeys.ToArray()); + var collectMethod = target.GetType().GetMethod("CollectUXHotkeys", BindingFlags.NonPublic | BindingFlags.Instance); + collectMethod.Invoke(target, null); + EditorUtility.SetDirty(_target); serializedObject.Update(); - Debug.Log($"[HotkeyBindComponent] 已找到 {uxHotkeys.Length} 个 UXHotkey 组件并绑定。"); } } diff --git a/Runtime/UXComponent/Hotkey/HotkeyBindComponent.cs b/Runtime/UXComponent/Hotkey/HotkeyBindComponent.cs index 2041d30..8115b8b 100644 --- a/Runtime/UXComponent/Hotkey/HotkeyBindComponent.cs +++ b/Runtime/UXComponent/Hotkey/HotkeyBindComponent.cs @@ -4,7 +4,7 @@ using UnityEngine; namespace AlicizaX.UI { - [DisallowMultipleComponent] + // [DisallowMultipleComponent] public class HotkeyBindComponent : MonoBehaviour { private UIHolderObjectBase _holderObjectBase; @@ -21,8 +21,8 @@ namespace AlicizaX.UI _holderObjectBase.OnWindowShowEvent -= BindHotKeys; _holderObjectBase.OnWindowClosedEvent -= UnBindHotKeys; } - [SerializeField] - private UXHotkeyButton[] hotButtons; + + [SerializeField] private UXHotkeyButton[] hotButtons; internal void BindHotKeys() { @@ -32,6 +32,14 @@ namespace AlicizaX.UI } } +#if UNITY_EDITOR + [ContextMenu("Bind HotKeys")] + private void CollectUXHotkeys() + { + hotButtons = gameObject.GetComponentsInChildren(true); + } +#endif + internal void UnBindHotKeys() { for (int i = 0; i < hotButtons.Length; i++)