com.alicizax.unity.ui.exten.../Editor/UX/Hotkey/HotkeyComponentEditor.cs

66 lines
2.3 KiB
C#
Raw Normal View History

2026-03-20 13:11:41 +08:00
using AlicizaX.UI.Runtime;
2026-03-19 19:50:32 +08:00
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace UnityEditor.UI
{
[CustomEditor(typeof(HotkeyComponent), true)]
public class HotkeyComponentEditor : UnityEditor.Editor
{
private SerializedProperty _hotkeyAction;
private SerializedProperty _hotkeyPressType;
private SerializedProperty _component;
private void OnEnable()
{
_component = serializedObject.FindProperty("_component");
_hotkeyAction = serializedObject.FindProperty("_hotkeyAction");
_hotkeyPressType = serializedObject.FindProperty("_hotkeyPressType");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
2026-03-20 13:11:41 +08:00
HotkeyComponent hotkeyComponent = (HotkeyComponent)target;
EditorGUILayout.HelpBox(
"Hotkeys auto-register to the nearest UIHolderObjectBase at runtime.",
MessageType.Info
);
if (hotkeyComponent.GetComponentInParent<UIHolderObjectBase>(true) == null)
{
EditorGUILayout.HelpBox(
"No UIHolderObjectBase was found in parents. This hotkey will not register at runtime.",
MessageType.Warning
);
}
2026-03-19 19:50:32 +08:00
if (_component.objectReferenceValue == null)
{
2026-03-20 13:11:41 +08:00
EditorGUILayout.HelpBox("No submit target was found on this object.", MessageType.Error);
2026-03-19 19:50:32 +08:00
if (hotkeyComponent.TryGetComponent(typeof(ISubmitHandler), out Component submitHandler))
{
_component.objectReferenceValue = submitHandler;
}
}
using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
{
EditorGUILayout.LabelField("Hotkey Setting", EditorStyles.boldLabel);
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.PropertyField(_component, new GUIContent("Component"));
EditorGUI.EndDisabledGroup();
2026-03-20 13:11:41 +08:00
EditorGUILayout.PropertyField(_hotkeyAction, new GUIContent("Input Action"));
EditorGUILayout.PropertyField(_hotkeyPressType, new GUIContent("Press Type"));
2026-03-19 19:50:32 +08:00
}
serializedObject.ApplyModifiedProperties();
}
}
}