AxibugEmuOnline/AxibugEmuOnline.Client/Assets/Runtime/Input/DefaultInput.cs
2024-06-28 18:08:25 +08:00

50 lines
1.3 KiB
C#

using System;
using UnityEngine;
namespace AxibugEmuOnline.Client.UNES.Input
{
public class DefaultInput : BaseInput
{
private KeyCode[] _keyCodes
{
get
{
if (_keyCodeCache == null)
{
var array = Enum.GetValues(typeof(KeyCode));
_keyCodeCache = new KeyCode[array.Length];
for (var i = 0; i < array.Length; i++)
{
_keyCodeCache[i] = (KeyCode)array.GetValue(i);
}
}
return _keyCodeCache;
}
}
private KeyCode[] _keyCodeCache;
public override void HandlerKeyDown(Action<KeyCode> onKeyDown)
{
foreach (var keyCode in _keyCodes)
{
if (UnityEngine.Input.GetKeyDown(keyCode))
{
onKeyDown(keyCode);
}
}
}
public override void HandlerKeyUp(Action<KeyCode> onKeyUp)
{
foreach (var keyCode in _keyCodes)
{
if (UnityEngine.Input.GetKeyUp(keyCode))
{
onKeyUp(keyCode);
}
}
}
}
}