分离Hotkey脱离扩展组件

This commit is contained in:
陈思海 2026-03-19 19:50:32 +08:00
parent 7b4feec0f0
commit bc554a5062
9 changed files with 90 additions and 118 deletions

View File

@ -20,12 +20,6 @@ namespace UnityEditor.UI
{
SerializedProperty m_OnClickProperty;
#if INPUTSYSTEM_SUPPORT
private SerializedProperty _hotKeyRefrence;
private SerializedProperty _hotkeyPressType;
#endif
private SerializedProperty hoverAudioClip;
private SerializedProperty clickAudioClip;
@ -35,12 +29,6 @@ namespace UnityEditor.UI
m_OnClickProperty = serializedObject.FindProperty("m_OnClick");
#if INPUTSYSTEM_SUPPORT
_hotKeyRefrence = serializedObject.FindProperty("_hotkeyAction");
_hotkeyPressType = serializedObject.FindProperty("_hotkeyPressType");
#endif
hoverAudioClip = serializedObject.FindProperty("hoverAudioClip");
clickAudioClip = serializedObject.FindProperty("clickAudioClip");
@ -64,15 +52,6 @@ namespace UnityEditor.UI
serializedObject.Update();
EditorGUILayout.PropertyField(m_OnClickProperty);
#if INPUTSYSTEM_SUPPORT
using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
{
EditorGUILayout.LabelField("Hotkey Setting", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(_hotKeyRefrence, new GUIContent("InputAction"));
EditorGUILayout.PropertyField(_hotkeyPressType, new GUIContent("PressType"));
}
#endif
serializedObject.ApplyModifiedProperties();
}

View File

@ -0,0 +1,49 @@
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();
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 939657bb1b5f4ad5b0836fa8fae2bef3
timeCreated: 1773919464

View File

@ -17,11 +17,6 @@ namespace UnityEditor.UI
SerializedProperty m_GroupProperty;
SerializedProperty m_IsOnProperty;
#if INPUTSYSTEM_SUPPORT
private SerializedProperty _hotKeyRefrence;
private SerializedProperty _hotkeyPressType;
#endif
private SerializedProperty hoverAudioClip;
private SerializedProperty clickAudioClip;
@ -35,11 +30,6 @@ namespace UnityEditor.UI
m_IsOnProperty = serializedObject.FindProperty("m_IsOn");
m_OnValueChangedProperty = serializedObject.FindProperty("onValueChanged");
#if INPUTSYSTEM_SUPPORT
_hotKeyRefrence = serializedObject.FindProperty("_hotkeyAction");
_hotkeyPressType = serializedObject.FindProperty("_hotkeyPressType");
#endif
hoverAudioClip = serializedObject.FindProperty("hoverAudioClip");
clickAudioClip = serializedObject.FindProperty("clickAudioClip");
@ -62,15 +52,6 @@ namespace UnityEditor.UI
serializedObject.Update();
EditorGUILayout.PropertyField(m_OnValueChangedProperty);
#if INPUTSYSTEM_SUPPORT
using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
{
EditorGUILayout.LabelField("Hotkey Setting", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(_hotKeyRefrence, new GUIContent("InputAction"));
EditorGUILayout.PropertyField(_hotkeyPressType, new GUIContent("PressType"));
}
#endif
serializedObject.ApplyModifiedProperties();
}

View File

@ -5,48 +5,11 @@ using AlicizaX.UI;
using AlicizaX.UI.Extension;
using UnityEngine.EventSystems;
#if INPUTSYSTEM_SUPPORT
using UnityEngine.InputSystem;
#endif
namespace UnityEngine.UI
{
[AddComponentMenu("UI/UXButton", 30)]
public class UXButton : UXSelectable, IPointerClickHandler, ISubmitHandler, IButton
#if INPUTSYSTEM_SUPPORT
, IHotkeyTrigger
#endif
{
#if INPUTSYSTEM_SUPPORT
InputActionReference IHotkeyTrigger.HotkeyAction
{
get => _hotkeyAction;
set => _hotkeyAction = value;
}
EHotkeyPressType IHotkeyTrigger.HotkeyPressType
{
get => _hotkeyPressType;
set => _hotkeyPressType = value;
}
void IHotkeyTrigger.HotkeyActionTrigger()
{
if (interactable)
{
OnSubmit(null);
}
}
[SerializeField] internal InputActionReference _hotkeyAction;
[SerializeField] internal EHotkeyPressType _hotkeyPressType;
public InputActionReference HotKeyRefrence
{
get { return _hotkeyAction; }
}
#endif
[SerializeField] private AudioClip hoverAudioClip;
[SerializeField] private AudioClip clickAudioClip;

View File

@ -1,22 +1,12 @@
using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
#if INPUTSYSTEM_SUPPORT
using UnityEngine.InputSystem;
#endif
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace UnityEngine.UI
{
[AddComponentMenu("UI/UXToggle", 30)]
[RequireComponent(typeof(RectTransform))]
public class UXToggle : UXSelectable, IPointerClickHandler, ISubmitHandler, ICanvasElement
#if INPUTSYSTEM_SUPPORT
, IHotkeyTrigger
#endif
{
[Serializable]
public class ToggleEvent : UnityEvent<bool>
@ -249,36 +239,6 @@ namespace UnityEngine.UI
UXComponentExtensionsHelper.AudioHelper.PlayAudio(clip);
}
#if INPUTSYSTEM_SUPPORT
InputActionReference IHotkeyTrigger.HotkeyAction
{
get => _hotkeyAction;
set => _hotkeyAction = value;
}
EHotkeyPressType IHotkeyTrigger.HotkeyPressType
{
get => _hotkeyPressType;
set => _hotkeyPressType = value;
}
void IHotkeyTrigger.HotkeyActionTrigger()
{
if (interactable)
{
OnSubmit(null);
}
}
[SerializeField] internal InputActionReference _hotkeyAction;
[SerializeField] internal EHotkeyPressType _hotkeyPressType;
public InputActionReference HotKeyRefrence
{
get { return _hotkeyAction; }
}
#endif
[SerializeField] private AudioClip hoverAudioClip;
[SerializeField] private AudioClip clickAudioClip;

View File

@ -0,0 +1,34 @@
using System;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
namespace UnityEngine.UI
{
[DisallowMultipleComponent]
public sealed class HotkeyComponent : MonoBehaviour, IHotkeyTrigger
{
[SerializeField] private Component _component;
[SerializeField] private InputActionReference _hotkeyAction;
[SerializeField] private EHotkeyPressType _hotkeyPressType;
public InputActionReference HotkeyAction
{
get => _hotkeyAction;
set => _hotkeyAction = value;
}
EHotkeyPressType IHotkeyTrigger.HotkeyPressType
{
get => _hotkeyPressType;
set => _hotkeyPressType = value;
}
void IHotkeyTrigger.HotkeyActionTrigger()
{
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ad0e473486c04dc19b468f2b20675091
timeCreated: 1773912951

View File

@ -5,7 +5,7 @@ namespace UnityEngine.UI
{
public interface IHotkeyTrigger
{
internal InputActionReference HotkeyAction { get; set; }
public InputActionReference HotkeyAction { get; }
internal EHotkeyPressType HotkeyPressType { get; set; }
internal void HotkeyActionTrigger();
}