com.alicizax.unity.ui.exten.../Runtime/UXComponent/Hotkey/HotkeyComponent.cs

38 lines
928 B
C#

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()
{
if (_component is ISubmitHandler submitHandler)
{
submitHandler.OnSubmit(null);
}
}
}
}