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

50 lines
1.8 KiB
C#

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();
if (_component.objectReferenceValue == null)
{
EditorGUILayout.HelpBox("物体身上不存在ISubmitHandler得到组件", MessageType.Error);
HotkeyComponent hotkeyComponent = (HotkeyComponent)target;
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();
EditorGUILayout.PropertyField(_hotkeyAction, new GUIContent("输入映射"));
EditorGUILayout.PropertyField(_hotkeyPressType, new GUIContent("触发类型"));
}
serializedObject.ApplyModifiedProperties();
}
}
}