分离Hotkey脱离扩展组件
This commit is contained in:
parent
7b4feec0f0
commit
bc554a5062
@ -20,12 +20,6 @@ namespace UnityEditor.UI
|
|||||||
{
|
{
|
||||||
SerializedProperty m_OnClickProperty;
|
SerializedProperty m_OnClickProperty;
|
||||||
|
|
||||||
|
|
||||||
#if INPUTSYSTEM_SUPPORT
|
|
||||||
private SerializedProperty _hotKeyRefrence;
|
|
||||||
private SerializedProperty _hotkeyPressType;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
private SerializedProperty hoverAudioClip;
|
private SerializedProperty hoverAudioClip;
|
||||||
private SerializedProperty clickAudioClip;
|
private SerializedProperty clickAudioClip;
|
||||||
|
|
||||||
@ -35,12 +29,6 @@ namespace UnityEditor.UI
|
|||||||
|
|
||||||
m_OnClickProperty = serializedObject.FindProperty("m_OnClick");
|
m_OnClickProperty = serializedObject.FindProperty("m_OnClick");
|
||||||
|
|
||||||
|
|
||||||
#if INPUTSYSTEM_SUPPORT
|
|
||||||
_hotKeyRefrence = serializedObject.FindProperty("_hotkeyAction");
|
|
||||||
_hotkeyPressType = serializedObject.FindProperty("_hotkeyPressType");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
hoverAudioClip = serializedObject.FindProperty("hoverAudioClip");
|
hoverAudioClip = serializedObject.FindProperty("hoverAudioClip");
|
||||||
clickAudioClip = serializedObject.FindProperty("clickAudioClip");
|
clickAudioClip = serializedObject.FindProperty("clickAudioClip");
|
||||||
|
|
||||||
@ -64,15 +52,6 @@ namespace UnityEditor.UI
|
|||||||
serializedObject.Update();
|
serializedObject.Update();
|
||||||
EditorGUILayout.PropertyField(m_OnClickProperty);
|
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();
|
serializedObject.ApplyModifiedProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
49
Editor/UX/Hotkey/HotkeyComponentEditor.cs
Normal file
49
Editor/UX/Hotkey/HotkeyComponentEditor.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
Editor/UX/Hotkey/HotkeyComponentEditor.cs.meta
Normal file
3
Editor/UX/Hotkey/HotkeyComponentEditor.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 939657bb1b5f4ad5b0836fa8fae2bef3
|
||||||
|
timeCreated: 1773919464
|
||||||
@ -17,11 +17,6 @@ namespace UnityEditor.UI
|
|||||||
SerializedProperty m_GroupProperty;
|
SerializedProperty m_GroupProperty;
|
||||||
SerializedProperty m_IsOnProperty;
|
SerializedProperty m_IsOnProperty;
|
||||||
|
|
||||||
#if INPUTSYSTEM_SUPPORT
|
|
||||||
private SerializedProperty _hotKeyRefrence;
|
|
||||||
private SerializedProperty _hotkeyPressType;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
private SerializedProperty hoverAudioClip;
|
private SerializedProperty hoverAudioClip;
|
||||||
private SerializedProperty clickAudioClip;
|
private SerializedProperty clickAudioClip;
|
||||||
|
|
||||||
@ -35,11 +30,6 @@ namespace UnityEditor.UI
|
|||||||
m_IsOnProperty = serializedObject.FindProperty("m_IsOn");
|
m_IsOnProperty = serializedObject.FindProperty("m_IsOn");
|
||||||
m_OnValueChangedProperty = serializedObject.FindProperty("onValueChanged");
|
m_OnValueChangedProperty = serializedObject.FindProperty("onValueChanged");
|
||||||
|
|
||||||
#if INPUTSYSTEM_SUPPORT
|
|
||||||
_hotKeyRefrence = serializedObject.FindProperty("_hotkeyAction");
|
|
||||||
_hotkeyPressType = serializedObject.FindProperty("_hotkeyPressType");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
hoverAudioClip = serializedObject.FindProperty("hoverAudioClip");
|
hoverAudioClip = serializedObject.FindProperty("hoverAudioClip");
|
||||||
clickAudioClip = serializedObject.FindProperty("clickAudioClip");
|
clickAudioClip = serializedObject.FindProperty("clickAudioClip");
|
||||||
|
|
||||||
@ -62,15 +52,6 @@ namespace UnityEditor.UI
|
|||||||
serializedObject.Update();
|
serializedObject.Update();
|
||||||
EditorGUILayout.PropertyField(m_OnValueChangedProperty);
|
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();
|
serializedObject.ApplyModifiedProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,48 +5,11 @@ using AlicizaX.UI;
|
|||||||
using AlicizaX.UI.Extension;
|
using AlicizaX.UI.Extension;
|
||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
|
|
||||||
#if INPUTSYSTEM_SUPPORT
|
|
||||||
using UnityEngine.InputSystem;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace UnityEngine.UI
|
namespace UnityEngine.UI
|
||||||
{
|
{
|
||||||
[AddComponentMenu("UI/UXButton", 30)]
|
[AddComponentMenu("UI/UXButton", 30)]
|
||||||
public class UXButton : UXSelectable, IPointerClickHandler, ISubmitHandler, IButton
|
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 hoverAudioClip;
|
||||||
[SerializeField] private AudioClip clickAudioClip;
|
[SerializeField] private AudioClip clickAudioClip;
|
||||||
|
|
||||||
|
|||||||
@ -1,22 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.Events;
|
using UnityEngine.Events;
|
||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
#if INPUTSYSTEM_SUPPORT
|
|
||||||
using UnityEngine.InputSystem;
|
|
||||||
#endif
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
using UnityEditor;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace UnityEngine.UI
|
namespace UnityEngine.UI
|
||||||
{
|
{
|
||||||
[AddComponentMenu("UI/UXToggle", 30)]
|
[AddComponentMenu("UI/UXToggle", 30)]
|
||||||
[RequireComponent(typeof(RectTransform))]
|
[RequireComponent(typeof(RectTransform))]
|
||||||
public class UXToggle : UXSelectable, IPointerClickHandler, ISubmitHandler, ICanvasElement
|
public class UXToggle : UXSelectable, IPointerClickHandler, ISubmitHandler, ICanvasElement
|
||||||
#if INPUTSYSTEM_SUPPORT
|
|
||||||
, IHotkeyTrigger
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class ToggleEvent : UnityEvent<bool>
|
public class ToggleEvent : UnityEvent<bool>
|
||||||
@ -249,36 +239,6 @@ namespace UnityEngine.UI
|
|||||||
UXComponentExtensionsHelper.AudioHelper.PlayAudio(clip);
|
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 hoverAudioClip;
|
||||||
[SerializeField] private AudioClip clickAudioClip;
|
[SerializeField] private AudioClip clickAudioClip;
|
||||||
|
|||||||
34
Runtime/UXComponent/Hotkey/HotkeyComponent.cs
Normal file
34
Runtime/UXComponent/Hotkey/HotkeyComponent.cs
Normal 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()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
Runtime/UXComponent/Hotkey/HotkeyComponent.cs.meta
Normal file
3
Runtime/UXComponent/Hotkey/HotkeyComponent.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ad0e473486c04dc19b468f2b20675091
|
||||||
|
timeCreated: 1773912951
|
||||||
@ -5,7 +5,7 @@ namespace UnityEngine.UI
|
|||||||
{
|
{
|
||||||
public interface IHotkeyTrigger
|
public interface IHotkeyTrigger
|
||||||
{
|
{
|
||||||
internal InputActionReference HotkeyAction { get; set; }
|
public InputActionReference HotkeyAction { get; }
|
||||||
internal EHotkeyPressType HotkeyPressType { get; set; }
|
internal EHotkeyPressType HotkeyPressType { get; set; }
|
||||||
internal void HotkeyActionTrigger();
|
internal void HotkeyActionTrigger();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user