forked from sin365/AxibugEmuOnline
Input系统代码迭代
This commit is contained in:
parent
cf8127c553
commit
924727eb7c
@ -27,8 +27,6 @@ namespace AxibugEmuOnline.Client.InputDevices
|
||||
{
|
||||
internal KeyCode m_keycode;
|
||||
|
||||
public override bool Performing => Device.Resolver.GetKey(Device as KeyBoard, m_keycode);
|
||||
|
||||
internal KeyboardKey(KeyCode listenKey, KeyBoard keyboard)
|
||||
: base(keyboard)
|
||||
{
|
||||
@ -36,16 +34,6 @@ namespace AxibugEmuOnline.Client.InputDevices
|
||||
}
|
||||
|
||||
public override string ControlName => m_keycode.ToString();
|
||||
|
||||
public override Vector2 GetVector2()
|
||||
{
|
||||
return default(Vector2);
|
||||
}
|
||||
|
||||
public override float GetFlaot()
|
||||
{
|
||||
return Performing ? 1 : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,6 @@ namespace AxibugEmuOnline.Client.InputDevices
|
||||
public Button Right { get; private set; }
|
||||
public Button Down { get; private set; }
|
||||
public Button Left { get; private set; }
|
||||
|
||||
public Stick LeftStick { get; private set; }
|
||||
public Stick RightStick { get; private set; }
|
||||
|
||||
@ -31,54 +30,40 @@ namespace AxibugEmuOnline.Client.InputDevices
|
||||
{
|
||||
List<InputControl> result = new List<InputControl>();
|
||||
|
||||
Cross = new Button(KeyCode.Joystick1Button0, this, "X");
|
||||
Circle = new Button(KeyCode.Joystick1Button1, this, "⭕");
|
||||
Square = new Button(KeyCode.Joystick1Button2, this, "□");
|
||||
Triangle = new Button(KeyCode.Joystick1Button3, this, "△");
|
||||
Cross = new Button(this, "X");
|
||||
Circle = new Button(this, "⭕");
|
||||
Square = new Button(this, "□");
|
||||
Triangle = new Button(this, "△");
|
||||
|
||||
L = new Button(KeyCode.Joystick1Button4, this, "L");
|
||||
R = new Button(KeyCode.Joystick1Button5, this, "R");
|
||||
L = new Button(this, "L");
|
||||
R = new Button(this, "R");
|
||||
|
||||
Select = new Button(KeyCode.Joystick1Button6, this, "SELECT");
|
||||
Start = new Button(KeyCode.Joystick1Button7, this, "START");
|
||||
Select = new Button(this, "SELECT");
|
||||
Start = new Button(this, "START");
|
||||
|
||||
Up = new Button(KeyCode.Joystick1Button8, this, "UP");
|
||||
Right = new Button(KeyCode.Joystick1Button9, this, "RIGHT");
|
||||
Down = new Button(KeyCode.Joystick1Button10, this, "DOWN");
|
||||
Left = new Button(KeyCode.Joystick1Button11, this, "LEFT");
|
||||
Up = new Button(this, "UP");
|
||||
Right = new Button(this, "RIGHT");
|
||||
Down = new Button(this, "DOWN");
|
||||
Left = new Button(this, "LEFT");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public class Button : InputControl
|
||||
{
|
||||
private KeyCode m_keyCode;
|
||||
private string m_controlName;
|
||||
internal string m_controlName;
|
||||
|
||||
public Button(KeyCode keycode, InputDevice device, string controlName) : base(device)
|
||||
public Button(InputDevice device, string controlName) : base(device)
|
||||
{
|
||||
m_keyCode = keycode;
|
||||
m_controlName = controlName;
|
||||
}
|
||||
|
||||
public override bool Performing => Input.GetKey(m_keyCode);
|
||||
|
||||
public override Vector2 GetVector2()
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
public override float GetFlaot()
|
||||
{
|
||||
return Performing ? 1 : 0;
|
||||
}
|
||||
|
||||
public override string ControlName => m_controlName;
|
||||
}
|
||||
|
||||
public class Stick : InputControl
|
||||
{
|
||||
private bool m_left;
|
||||
internal bool m_left;
|
||||
|
||||
public VirtualButton UP { get; private set; }
|
||||
public VirtualButton Down { get; private set; }
|
||||
@ -112,31 +97,6 @@ namespace AxibugEmuOnline.Client.InputDevices
|
||||
Right.Update();
|
||||
}
|
||||
|
||||
public override bool Performing => GetVector2().x != 0 || GetVector2().y != 0;
|
||||
|
||||
public override Vector2 GetVector2()
|
||||
{
|
||||
Vector2 result = Vector2.zero;
|
||||
|
||||
if (m_left)
|
||||
{
|
||||
result.x = Input.GetAxis("Horizontal");
|
||||
result.y = Input.GetAxis("Vertical");
|
||||
}
|
||||
else
|
||||
{
|
||||
result.x = Input.GetAxis("HorizontalR");
|
||||
result.y = Input.GetAxis("VerticalR");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override float GetFlaot()
|
||||
{
|
||||
return Performing ? 1 : 0;
|
||||
}
|
||||
|
||||
public override string ControlName => $"{nameof(Stick)}_{(m_left ? "left" : "right")}";
|
||||
|
||||
public class VirtualButton : InputControl
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AxibugEmuOnline.Client.InputDevices
|
||||
@ -129,13 +128,13 @@ namespace AxibugEmuOnline.Client.InputDevices
|
||||
|
||||
bool m_performingLastFrame;
|
||||
/// <summary> 获取该控件是否在当前调用帧是否处于活动状态 </summary>
|
||||
public abstract bool Performing { get; }
|
||||
public virtual bool Performing => Device.Resolver.CheckPerforming(this);
|
||||
|
||||
/// <summary> 获得该控件的以二维向量表达的值 </summary>
|
||||
/// <returns></returns>
|
||||
public abstract Vector2 GetVector2();
|
||||
public virtual Vector2 GetVector2() => Device.Resolver.GetVector2(this);
|
||||
/// <summary> 获得该控件的以浮点数表达的值 </summary>
|
||||
public abstract float GetFlaot();
|
||||
public virtual float GetFlaot() => Device.Resolver.GetFloat(this);
|
||||
|
||||
internal void Update()
|
||||
{
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace AxibugEmuOnline.Client.InputDevices
|
||||
{
|
||||
@ -55,13 +56,9 @@ namespace AxibugEmuOnline.Client.InputDevices
|
||||
OnDeviceConnected?.Invoke(connectDevice);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取一个键盘设备的指定按键当前调用帧是否处于按下状态
|
||||
/// </summary>
|
||||
/// <param name="keyboard">键盘设备实例,来自Resolver提供的设备实例</param>
|
||||
/// <param name="key">键盘按键枚举值</param>
|
||||
public abstract bool GetKey(KeyBoard keyboard, KeyCode key);
|
||||
|
||||
public abstract bool CheckPerforming<CONTROLLER>(CONTROLLER control) where CONTROLLER : InputDevice.InputControl;
|
||||
public abstract Vector2 GetVector2<CONTROLLER>(CONTROLLER control) where CONTROLLER : InputDevice.InputControl;
|
||||
public abstract float GetFloat<CONTROLLER>(CONTROLLER control) where CONTROLLER : InputDevice.InputControl;
|
||||
/// <summary>
|
||||
/// 获得输入设备的唯一名称
|
||||
/// </summary>
|
||||
|
@ -1,6 +1,7 @@
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.InputSystem.Controls;
|
||||
using IP = UnityEngine.InputSystem.InputSystem;
|
||||
using IPDevice = UnityEngine.InputSystem.InputDevice;
|
||||
@ -68,18 +69,37 @@ namespace AxibugEmuOnline.Client.InputDevices.ForInputSystem
|
||||
return m_devices.Values;
|
||||
}
|
||||
|
||||
public override bool GetKey(KeyBoard keyboard, KeyCode key)
|
||||
public override bool CheckPerforming<CONTROLLER>(CONTROLLER control)
|
||||
{
|
||||
if (m_devices.TryGetKey(keyboard, out var ipdev))
|
||||
if (control.Device is KeyBoard keyboard)
|
||||
{
|
||||
var ipKeyboard = ipdev as IPKeyboard;
|
||||
if (ipKeyboard == null) return false;
|
||||
if (control is KeyBoard.KeyboardKey key)
|
||||
{
|
||||
if (m_devices.TryGetKey(keyboard, out var ipdev))
|
||||
{
|
||||
var ipKeyboard = ipdev as IPKeyboard;
|
||||
if (ipKeyboard == null) return false;
|
||||
|
||||
var k = GetIPKeyboardKey(ipKeyboard, key);
|
||||
return k.isPressed;
|
||||
var k = GetIPKeyboardKey(ipKeyboard, key.m_keycode);
|
||||
return k.isPressed;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public override Vector2 GetVector2<CONTROLLER>(CONTROLLER control)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public override float GetFloat<CONTROLLER>(CONTROLLER control)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework.Internal;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using static Essgee.Emulation.Audio.DMGAudio;
|
||||
using static VirtualNes.Core.APU_INTERNAL;
|
||||
|
||||
namespace AxibugEmuOnline.Client.InputDevices.ForPSV
|
||||
{
|
||||
@ -24,16 +27,71 @@ namespace AxibugEmuOnline.Client.InputDevices.ForPSV
|
||||
return device == m_psvController;
|
||||
}
|
||||
|
||||
public override bool GetKey(KeyBoard keyboard, KeyCode key)
|
||||
{
|
||||
return Input.GetKeyDown(key);
|
||||
}
|
||||
|
||||
public override string GetDeviceName(InputDevice inputDevice)
|
||||
{
|
||||
Debug.Assert(inputDevice == m_psvController, "只支持psv控制器");
|
||||
|
||||
return nameof(PSVController);
|
||||
}
|
||||
|
||||
public override bool CheckPerforming<CONTROLLER>(CONTROLLER control)
|
||||
{
|
||||
if (control.Device is PSVController psvCon)
|
||||
{
|
||||
if (control is PSVController.Button button)
|
||||
{
|
||||
if (button == psvCon.Cross) return Input.GetKey(KeyCode.Joystick1Button0);
|
||||
else if (button == psvCon.Circle) return Input.GetKey(KeyCode.Joystick1Button1);
|
||||
else if (button == psvCon.Square) return Input.GetKey(KeyCode.Joystick1Button2);
|
||||
else if (button == psvCon.Triangle) return Input.GetKey(KeyCode.Joystick1Button3);
|
||||
else if (button == psvCon.L) return Input.GetKey(KeyCode.Joystick1Button4);
|
||||
else if (button == psvCon.R) return Input.GetKey(KeyCode.Joystick1Button5);
|
||||
else if (button == psvCon.Select) return Input.GetKey(KeyCode.Joystick1Button6);
|
||||
else if (button == psvCon.Start) return Input.GetKey(KeyCode.Joystick1Button7);
|
||||
else if (button == psvCon.Up) return Input.GetKey(KeyCode.Joystick1Button8);
|
||||
else if (button == psvCon.Right) return Input.GetKey(KeyCode.Joystick1Button9);
|
||||
else if (button == psvCon.Down) return Input.GetKey(KeyCode.Joystick1Button10);
|
||||
else if (button == psvCon.Left) return Input.GetKey(KeyCode.Joystick1Button11);
|
||||
}
|
||||
else if (control is PSVController.Stick stick)
|
||||
{
|
||||
var vec2 = stick.GetVector2();
|
||||
return vec2.x != 0 || vec2.y != 0;
|
||||
}
|
||||
}
|
||||
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public override Vector2 GetVector2<CONTROLLER>(CONTROLLER control)
|
||||
{
|
||||
if (control.Device is PSVController)
|
||||
{
|
||||
if (control is PSVController.Stick stick)
|
||||
{
|
||||
Vector2 result = Vector2.zero;
|
||||
|
||||
if (stick.m_left)
|
||||
{
|
||||
result.x = Input.GetAxis("Joy1 Axis X");
|
||||
result.y = Input.GetAxis("Joy1 Axis Y");
|
||||
}
|
||||
else
|
||||
{
|
||||
result.x = Input.GetAxis("Joy1 Axis 4");
|
||||
result.y = Input.GetAxis("Joy1 Axis 5");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public override float GetFloat<CONTROLLER>(CONTROLLER control)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user