实现统一的Input管理,KeyCode,Axis,Ugui虚拟按钮,做统一封装,外部不关心,另外MAME核心的Input已经换成这套

This commit is contained in:
sin365 2025-03-05 00:09:07 +08:00
parent b0d1cc6131
commit 49875351c3
14 changed files with 547 additions and 68 deletions

View File

@ -22,6 +22,7 @@ namespace AxibugEmuOnline.Client.ClientCore
public static AppLogin login;
public static AppChat chat;
public static UserDataManager user;
public static AppInput input;
public static AppEmu emu;
public static HttpAPI httpAPI;
public static CacheManager CacheMgr;
@ -83,6 +84,7 @@ namespace AxibugEmuOnline.Client.ClientCore
login = new AppLogin();
chat = new AppChat();
user = new UserDataManager();
input = new AppInput();
emu = new AppEmu();
httpAPI = new HttpAPI();
if (bUseLocalWebApi)

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0a5208f1ea0c95b4fba6c793b1f7f3f7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fe1927652aa0d4d46955419a18ee7802
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,54 @@
using System;
using System.Runtime.InteropServices;
using UnityEngine;
namespace Assets.Script.AppMain.AxiInput
{
[StructLayout(LayoutKind.Explicit, Size = 8)]
public struct AxiInput
{
[FieldOffset(0)]
public UInt64 all;
[FieldOffset(0)]
public AxiInputType type;
[FieldOffset(1)]
public KeyCode KeyCodeValue;
[FieldOffset(1)]
public AxiInputAxisType AxisType;
[FieldOffset(1)]
public AxiInputUGuiBtnType UguiBtn;
}
public enum AxiInputType : byte
{
UNITY_KEYCODE,
UNITY_AXIS,//Input.GetAxis
UNITY_UGUI_BTN,//UGUI 的BTN事件
}
public enum AxiInputAxisType : byte
{
LEFT,
RIGHT,
UP,
DOWN,
}
public enum AxiInputUGuiBtnType : byte
{
UP,
DOWN,
LEFT,
RIGHT,
BTN_1,
BTN_2,
BTN_3,
BTN_4,
BTN_5,
BTN_6,
POTION_1,
POTION_2,
POTION_3,
POTION_4,
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: ec9c487241d75d34e9ae2ee3c047ec1b

View File

@ -0,0 +1,71 @@
using UnityEngine;
namespace Assets.Script.AppMain.AxiInput
{
public static class AxiInputEx
{
public static AxiInput ByKeyCode(KeyCode keycode)
{
AxiInput data = new AxiInput();
data.all = 0;
data.type = AxiInputType.UNITY_KEYCODE;
data.KeyCodeValue = keycode;
return data;
}
public static AxiInput ByAxis(AxiInputAxisType axisType)
{
AxiInput data = new AxiInput();
data.all = 0;
data.type = AxiInputType.UNITY_AXIS;
data.AxisType = axisType;
return data;
}
public static AxiInput ByUGUIBtn(AxiInputUGuiBtnType btnType)
{
AxiInput data = new AxiInput();
data.all = 0;
data.type = AxiInputType.UNITY_UGUI_BTN;
data.UguiBtn = btnType;
return data;
}
public static bool IsKeyDown(this AxiInput axiInput)
{
switch (axiInput.type)
{
case AxiInputType.UNITY_KEYCODE:
return Input.GetKeyDown(axiInput.KeyCodeValue);
case AxiInputType.UNITY_AXIS://AXIS 不考虑KeyDown情况
{
switch (axiInput.AxisType)
{
case AxiInputAxisType.RIGHT: return Input.GetAxis("Horizontal") > 0;
case AxiInputAxisType.LEFT: return Input.GetAxis("Horizontal") < 0;
case AxiInputAxisType.UP: return Input.GetAxis("Vertical") > 0;
case AxiInputAxisType.DOWN: return Input.GetAxis("Vertical") < 0;
default: return false;
}
}
case AxiInputType.UNITY_UGUI_BTN:
return AxiInputUGUICenter.IsKeyDown(axiInput.UguiBtn);
default:
return false;
}
}
public static bool IsKey(this AxiInput axiInput)
{
switch (axiInput.type)
{
case AxiInputType.UNITY_KEYCODE:
return Input.GetKey(axiInput.KeyCodeValue);
case AxiInputType.UNITY_AXIS://AXIS 不考虑KeyDown情况
return false;
case AxiInputType.UNITY_UGUI_BTN:
return AxiInputUGUICenter.IsKeyDown(axiInput.UguiBtn);
default:
return false;
}
}
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: f19df5371f3222747868da94fc86702f

View File

@ -0,0 +1,66 @@
using AxibugEmuOnline.Client.Manager;
using System.Collections.Generic;
namespace Assets.Script.AppMain.AxiInput
{
public static class AxiInputUGUICenter
{
static int handleSeed = 0;
static Dictionary<int, AxiInputUGUIHandleBase> dictHandle2AxiUgui = new Dictionary<int, AxiInputUGUIHandleBase>();
static Dictionary<AxiInputUGuiBtnType, List<AxiInputUGUIHandleBase>> dictBtnType2BtnList = new Dictionary<AxiInputUGuiBtnType, List<AxiInputUGUIHandleBase>>();
public static int GetNextSeed()
{
return ++handleSeed;
}
public static void RegHandle(AxiInputUGUIHandleBase uiHandle)
{
dictHandle2AxiUgui[uiHandle.Handle] = uiHandle;
List<AxiInputUGUIHandleBase> list;
if (dictBtnType2BtnList.TryGetValue(uiHandle.UguiBtnType, out list))
list = dictBtnType2BtnList[uiHandle.UguiBtnType] = new List<AxiInputUGUIHandleBase>();
if (!list.Contains(uiHandle))
list.Add(uiHandle);
}
public static void UnregHandle(AxiInputUGUIHandleBase uiHandle)
{
if (!dictHandle2AxiUgui.ContainsKey(uiHandle.Handle))
return;
dictHandle2AxiUgui.Remove(uiHandle.Handle);
List<AxiInputUGUIHandleBase> list;
if (dictBtnType2BtnList.TryGetValue(uiHandle.UguiBtnType, out list))
{
if (list.Contains(uiHandle))
list.Remove(uiHandle);
}
}
public static bool IsKeyDown(AxiInputUGuiBtnType btntype)
{
List<AxiInputUGUIHandleBase> list;
if (!dictBtnType2BtnList.TryGetValue(btntype, out list))
return false;
for (int i = 0; i < list.Count; i++)
{
if (list[i].IsKeyDown())
return true;
}
return false;
}
public static bool IsKey(AxiInputUGuiBtnType btntype)
{
List<AxiInputUGUIHandleBase> list;
if (!dictBtnType2BtnList.TryGetValue(btntype, out list))
return false;
for (int i = 0; i < list.Count; i++)
{
if (list[i].IsKey())
return true;
}
return false;
}
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0a5bf14cd30c06b498fda45eb5f4ac2a

View File

@ -0,0 +1,26 @@
using AxibugEmuOnline.Client.Manager;
using System;
namespace Assets.Script.AppMain.AxiInput
{
public abstract class AxiInputUGUIHandleBase : IDisposable
{
public int Handle { get; private set; }
public AxiInputUGuiBtnType UguiBtnType { get; private set; }
public AxiInputUGUIHandleBase(AxiInputUGuiBtnType uguiBtnType)
{
Handle = AxiInputUGUICenter.GetNextSeed();
this.UguiBtnType = uguiBtnType;
AxiInputUGUICenter.RegHandle(this);
}
public abstract bool IsKeyDown();
public abstract bool IsKey();
public void Dispose()
{
AxiInputUGUICenter.UnregHandle(this);
}
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: c9c6bc9404053b24ba77a0f86ad1daa8

View File

@ -1,12 +1,14 @@
using AxibugEmuOnline.Client;
using AxibugEmuOnline.Client.ClientCore;
using AxibugEmuOnline.Client.Event;
using AxibugEmuOnline.Client.Manager;
using AxiReplay;
using MAME.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using static AxibugEmuOnline.Client.Manager.MAMEKSingleKeysSeting;
public class UniKeyboard : MonoBehaviour, IKeyboard
{
@ -268,9 +270,9 @@ public class MameControllerMapper : IControllerSetuper
/// </summary>
public class MameSingleConoller : IController
{
public KeyCode INSERT_COIN, GAMESTART,
UP, DOWN, LEFT, RIGHT,
BTN_A, BTN_B, BTN_C, BTN_D, BTN_E, BTN_F;
//public KeyCode INSERT_COIN, GAMESTART,
//UP, DOWN, LEFT, RIGHT,
//BTN_A, BTN_B, BTN_C, BTN_D, BTN_E, BTN_F;
public ulong tg_INSERT_COIN, tg_GAMESTART,
tg_UP, tg_DOWN, tg_LEFT, tg_RIGHT,
@ -300,7 +302,10 @@ public class MameSingleConoller : IController
public int ControllerIndex
{
get { return mControllerIndex; }
set { mControllerIndex = value; this.LoadControlKeyForConfig(); }
set { mControllerIndex = value;
//this.LoadControlKeyForConfig();
//走统一配置
}
}
public MameSingleConoller(int controllerIndex)
{
@ -309,82 +314,100 @@ public class MameSingleConoller : IController
public bool AnyButtonDown()
{
if (Input.GetKeyDown(INSERT_COIN)) return true;
if (Input.GetKeyDown(GAMESTART)) return true;
if (Input.GetKeyDown(UP)) return true;
if (Input.GetKeyDown(DOWN)) return true;
if (Input.GetKeyDown(LEFT)) return true;
if (Input.GetKeyDown(RIGHT)) return true;
if (Input.GetKeyDown(BTN_A)) return true;
if (Input.GetKeyDown(BTN_B)) return true;
if (Input.GetKeyDown(BTN_C)) return true;
if (Input.GetKeyDown(BTN_D)) return true;
if (Input.GetKeyDown(BTN_E)) return true;
if (Input.GetKeyDown(BTN_F)) return true;
return false;
return App.input.mame.HadAnyKeyDown(ControllerIndex);
//if (Input.GetKeyDown(INSERT_COIN)) return true;
//if (Input.GetKeyDown(GAMESTART)) return true;
//if (Input.GetKeyDown(UP)) return true;
//if (Input.GetKeyDown(DOWN)) return true;
//if (Input.GetKeyDown(LEFT)) return true;
//if (Input.GetKeyDown(RIGHT)) return true;
//if (Input.GetKeyDown(BTN_A)) return true;
//if (Input.GetKeyDown(BTN_B)) return true;
//if (Input.GetKeyDown(BTN_C)) return true;
//if (Input.GetKeyDown(BTN_D)) return true;
//if (Input.GetKeyDown(BTN_E)) return true;
//if (Input.GetKeyDown(BTN_F)) return true;
//return false;
}
public ulong GetSingleAllInput()
{
if (!ConnectSlot.HasValue)
return 0;
CurrLocalSingleAllInput = 0;
if (Input.GetKey(INSERT_COIN)) CurrLocalSingleAllInput |= (ulong)tg_INSERT_COIN;
if (Input.GetKey(GAMESTART)) CurrLocalSingleAllInput |= (ulong)tg_GAMESTART;
if (Input.GetKey(UP)) CurrLocalSingleAllInput |= (ulong)tg_UP;
if (Input.GetKey(DOWN)) CurrLocalSingleAllInput |= (ulong)tg_DOWN;
if (Input.GetKey(LEFT)) CurrLocalSingleAllInput |= (ulong)tg_LEFT;
if (Input.GetKey(RIGHT)) CurrLocalSingleAllInput |= (ulong)tg_RIGHT;
if (Input.GetKey(BTN_A)) CurrLocalSingleAllInput |= (ulong)tg_BTN_A;
if (Input.GetKey(BTN_B)) CurrLocalSingleAllInput |= (ulong)tg_BTN_B;
if (Input.GetKey(BTN_C)) CurrLocalSingleAllInput |= (ulong)tg_BTN_C;
if (Input.GetKey(BTN_D)) CurrLocalSingleAllInput |= (ulong)tg_BTN_D;
if (Input.GetKey(BTN_E)) CurrLocalSingleAllInput |= (ulong)tg_BTN_E;
if (Input.GetKey(BTN_F)) CurrLocalSingleAllInput |= (ulong)tg_BTN_F;
MAMEKSingleKeysSeting keys = App.input.mame.controllers[ControllerIndex];
if (keys.GetKey(MAMEKSingleKey.INSERT_COIN)) CurrLocalSingleAllInput |= (ulong)tg_INSERT_COIN;
if (keys.GetKey(MAMEKSingleKey.GAMESTART)) CurrLocalSingleAllInput |= (ulong)tg_GAMESTART;
if (keys.GetKey(MAMEKSingleKey.UP)) CurrLocalSingleAllInput |= (ulong)tg_UP;
if (keys.GetKey(MAMEKSingleKey.DOWN)) CurrLocalSingleAllInput |= (ulong)tg_DOWN;
if (keys.GetKey(MAMEKSingleKey.LEFT)) CurrLocalSingleAllInput |= (ulong)tg_LEFT;
if (keys.GetKey(MAMEKSingleKey.RIGHT)) CurrLocalSingleAllInput |= (ulong)tg_RIGHT;
if (keys.GetKey(MAMEKSingleKey.BTN_A)) CurrLocalSingleAllInput |= (ulong)tg_BTN_A;
if (keys.GetKey(MAMEKSingleKey.BTN_B)) CurrLocalSingleAllInput |= (ulong)tg_BTN_B;
if (keys.GetKey(MAMEKSingleKey.BTN_C)) CurrLocalSingleAllInput |= (ulong)tg_BTN_C;
if (keys.GetKey(MAMEKSingleKey.BTN_D)) CurrLocalSingleAllInput |= (ulong)tg_BTN_D;
if (keys.GetKey(MAMEKSingleKey.BTN_E)) CurrLocalSingleAllInput |= (ulong)tg_BTN_E;
if (keys.GetKey(MAMEKSingleKey.BTN_F)) CurrLocalSingleAllInput |= (ulong)tg_BTN_F;
//if (Input.GetKey(INSERT_COIN)) CurrLocalSingleAllInput |= (ulong)tg_INSERT_COIN;
//if (Input.GetKey(GAMESTART)) CurrLocalSingleAllInput |= (ulong)tg_GAMESTART;
//if (Input.GetKey(UP)) CurrLocalSingleAllInput |= (ulong)tg_UP;
//if (Input.GetKey(DOWN)) CurrLocalSingleAllInput |= (ulong)tg_DOWN;
//if (Input.GetKey(LEFT)) CurrLocalSingleAllInput |= (ulong)tg_LEFT;
//if (Input.GetKey(RIGHT)) CurrLocalSingleAllInput |= (ulong)tg_RIGHT;
//if (Input.GetKey(BTN_A)) CurrLocalSingleAllInput |= (ulong)tg_BTN_A;
//if (Input.GetKey(BTN_B)) CurrLocalSingleAllInput |= (ulong)tg_BTN_B;
//if (Input.GetKey(BTN_C)) CurrLocalSingleAllInput |= (ulong)tg_BTN_C;
//if (Input.GetKey(BTN_D)) CurrLocalSingleAllInput |= (ulong)tg_BTN_D;
//if (Input.GetKey(BTN_E)) CurrLocalSingleAllInput |= (ulong)tg_BTN_E;
//if (Input.GetKey(BTN_F)) CurrLocalSingleAllInput |= (ulong)tg_BTN_F;
return CurrLocalSingleAllInput;
}
}
public static class MameSingleControllSetter
{
public static void LoadControlKeyForConfig(this MameSingleConoller singlecontrol)
{
//TODO µÈ´ýÖ§³ÖÅäÖ㬻òͳһ
switch (singlecontrol.ControllerIndex)
{
case 0:
singlecontrol.INSERT_COIN = KeyCode.Alpha5;
singlecontrol.GAMESTART = KeyCode.Alpha1;
singlecontrol.UP = KeyCode.W;
singlecontrol.DOWN = KeyCode.S;
singlecontrol.LEFT = KeyCode.A;
singlecontrol.RIGHT = KeyCode.D;
singlecontrol.BTN_A = KeyCode.J;
singlecontrol.BTN_B = KeyCode.K;
singlecontrol.BTN_C = KeyCode.L;
singlecontrol.BTN_D = KeyCode.U;
singlecontrol.BTN_E = KeyCode.I;
singlecontrol.BTN_F = KeyCode.O;
break;
case 1:
singlecontrol.INSERT_COIN = KeyCode.KeypadMultiply;
singlecontrol.GAMESTART = KeyCode.KeypadDivide;
singlecontrol.UP = KeyCode.UpArrow;
singlecontrol.DOWN = KeyCode.DownArrow;
singlecontrol.LEFT = KeyCode.LeftArrow;
singlecontrol.RIGHT = KeyCode.RightArrow;
singlecontrol.BTN_A = KeyCode.Keypad1;
singlecontrol.BTN_B = KeyCode.Keypad2;
singlecontrol.BTN_C = KeyCode.Keypad3;
singlecontrol.BTN_D = KeyCode.Keypad4;
singlecontrol.BTN_E = KeyCode.Keypad5;
singlecontrol.BTN_F = KeyCode.Keypad6;
break;
case 2:
break;
case 3:
break;
}
}
//不再需要
//public static void LoadControlKeyForConfig(this MameSingleConoller singlecontrol)
//{
// //TODO 等待支持配置,或统一
// switch (singlecontrol.ControllerIndex)
// {
// case 0:
// singlecontrol.INSERT_COIN = KeyCode.Alpha5;
// singlecontrol.GAMESTART = KeyCode.Alpha1;
// singlecontrol.UP = KeyCode.W;
// singlecontrol.DOWN = KeyCode.S;
// singlecontrol.LEFT = KeyCode.A;
// singlecontrol.RIGHT = KeyCode.D;
// singlecontrol.BTN_A = KeyCode.J;
// singlecontrol.BTN_B = KeyCode.K;
// singlecontrol.BTN_C = KeyCode.L;
// singlecontrol.BTN_D = KeyCode.U;
// singlecontrol.BTN_E = KeyCode.I;
// singlecontrol.BTN_F = KeyCode.O;
// break;
// case 1:
// singlecontrol.INSERT_COIN = KeyCode.KeypadMultiply;
// singlecontrol.GAMESTART = KeyCode.KeypadDivide;
// singlecontrol.UP = KeyCode.UpArrow;
// singlecontrol.DOWN = KeyCode.DownArrow;
// singlecontrol.LEFT = KeyCode.LeftArrow;
// singlecontrol.RIGHT = KeyCode.RightArrow;
// singlecontrol.BTN_A = KeyCode.Keypad1;
// singlecontrol.BTN_B = KeyCode.Keypad2;
// singlecontrol.BTN_C = KeyCode.Keypad3;
// singlecontrol.BTN_D = KeyCode.Keypad4;
// singlecontrol.BTN_E = KeyCode.Keypad5;
// singlecontrol.BTN_F = KeyCode.Keypad6;
// break;
// case 2:
// break;
// case 3:
// break;
// }
//}
public static void ResetTargetMotionKey(this MameSingleConoller singlecontrol)
{
if (!singlecontrol.ConnectSlot.HasValue)

View File

@ -0,0 +1,211 @@
using Assets.Script.AppMain.AxiInput;
using AxibugEmuOnline.Client.Common;
using System.Collections.Generic;
using UnityEngine;
using static AxibugEmuOnline.Client.Manager.MAMEKSingleKeysSeting;
namespace AxibugEmuOnline.Client.Manager
{
public class AppInput
{
public MAMEKMultiKeysSetting mame;
public AppInput()
{
mame = new MAMEKMultiKeysSetting();
LoadDefaultSetting();
}
public void LoadDefaultSetting()
{
mame.LoadDefaultSetting();
}
}
public interface MultiKeysSetting
{
bool HadAnyKeyDown(int index);
void ClearAll();
void LoadDefaultSetting();
}
public interface SingleKeysSetting
{
void ClearAll();
void SetKey(ulong Key, AxiInput input);
void ColletAllKey();
bool HadAnyKeyDown();
}
public class MAMEKMultiKeysSetting : MultiKeysSetting
{
public MAMEKSingleKeysSeting[] controllers;
public MAMEKMultiKeysSetting()
{
controllers = new MAMEKSingleKeysSeting[4];
for (int i = 0; i < controllers.Length; i++)
controllers[i] = new MAMEKSingleKeysSeting();
}
public bool HadAnyKeyDown(int index)
{
if (index >= controllers.Length)
return false;
return controllers[index].HadAnyKeyDown();
}
public void ClearAll()
{
controllers[0].ClearAll();
controllers[1].ClearAll();
controllers[2].ClearAll();
controllers[3].ClearAll();
}
public void LoadDefaultSetting()
{
ClearAll();
#if UNITY_PSP2 && !UNITY_EDITOR
//PSV 摇杆
controllers[0].SetKey((ulong)MAMEKSingleKey.GAMESTART, AxiInputEx.ByKeyCode(PSVitaKey.Start));
controllers[0].SetKey((ulong)MAMEKSingleKey.INSERT_COIN, AxiInputEx.ByKeyCode(PSVitaKey.Select));
controllers[0].SetKey((ulong)MAMEKSingleKey.UP, AxiInputEx.ByKeyCode(PSVitaKey.Up));
controllers[0].SetKey((ulong)MAMEKSingleKey.DOWN, AxiInputEx.ByKeyCode(PSVitaKey.Down));
controllers[0].SetKey((ulong)MAMEKSingleKey.LEFT, AxiInputEx.ByKeyCode(PSVitaKey.Left));
controllers[0].SetKey((ulong)MAMEKSingleKey.RIGHT, AxiInputEx.ByKeyCode(PSVitaKey.Right));
controllers[0].SetKey((ulong)MAMEKSingleKey.BTN_A, AxiInputEx.ByKeyCode(PSVitaKey.Block));
controllers[0].SetKey((ulong)MAMEKSingleKey.BTN_B, AxiInputEx.ByKeyCode(PSVitaKey.Cross));
controllers[0].SetKey((ulong)MAMEKSingleKey.BTN_C, AxiInputEx.ByKeyCode(PSVitaKey.Circle));
controllers[0].SetKey((ulong)MAMEKSingleKey.BTN_D, AxiInputEx.ByKeyCode(PSVitaKey.Triangle));
controllers[0].SetKey((ulong)MAMEKSingleKey.BTN_E, AxiInputEx.ByKeyCode(PSVitaKey.L));
controllers[0].SetKey((ulong)MAMEKSingleKey.BTN_F, AxiInputEx.ByKeyCode(PSVitaKey.R));
//PSV 摇杆
controllers[0].SetKey((ulong)MAMEKSingleKey.UP, AxiInputEx.ByAxis(AxiInputAxisType.UP));
controllers[0].SetKey((ulong)MAMEKSingleKey.DOWN, AxiInputEx.ByAxis(AxiInputAxisType.DOWN));
controllers[0].SetKey((ulong)MAMEKSingleKey.LEFT, AxiInputEx.ByAxis(AxiInputAxisType.LEFT));
controllers[0].SetKey((ulong)MAMEKSingleKey.RIGHT, AxiInputEx.ByAxis(AxiInputAxisType.RIGHT));
controllers[0].ColletAllKey();
return;
#endif
#region P1
//P1 键盘
controllers[0].SetKey((ulong)MAMEKSingleKey.GAMESTART, AxiInputEx.ByKeyCode(KeyCode.Alpha1));
controllers[0].SetKey((ulong)MAMEKSingleKey.INSERT_COIN, AxiInputEx.ByKeyCode(KeyCode.Alpha5));
controllers[0].SetKey((ulong)MAMEKSingleKey.UP, AxiInputEx.ByKeyCode(KeyCode.W));
controllers[0].SetKey((ulong)MAMEKSingleKey.DOWN, AxiInputEx.ByKeyCode(KeyCode.S));
controllers[0].SetKey((ulong)MAMEKSingleKey.LEFT, AxiInputEx.ByKeyCode(KeyCode.A));
controllers[0].SetKey((ulong)MAMEKSingleKey.RIGHT, AxiInputEx.ByKeyCode(KeyCode.D));
controllers[0].SetKey((ulong)MAMEKSingleKey.UP, AxiInputEx.ByKeyCode(KeyCode.G));
controllers[0].SetKey((ulong)MAMEKSingleKey.DOWN, AxiInputEx.ByKeyCode(KeyCode.V));
controllers[0].SetKey((ulong)MAMEKSingleKey.LEFT, AxiInputEx.ByKeyCode(KeyCode.C));
controllers[0].SetKey((ulong)MAMEKSingleKey.RIGHT, AxiInputEx.ByKeyCode(KeyCode.B));
controllers[0].SetKey((ulong)MAMEKSingleKey.BTN_A, AxiInputEx.ByKeyCode(KeyCode.J));
controllers[0].SetKey((ulong)MAMEKSingleKey.BTN_B, AxiInputEx.ByKeyCode(KeyCode.K));
controllers[0].SetKey((ulong)MAMEKSingleKey.BTN_C, AxiInputEx.ByKeyCode(KeyCode.L));
controllers[0].SetKey((ulong)MAMEKSingleKey.BTN_D, AxiInputEx.ByKeyCode(KeyCode.U));
controllers[0].SetKey((ulong)MAMEKSingleKey.BTN_E, AxiInputEx.ByKeyCode(KeyCode.I));
controllers[0].SetKey((ulong)MAMEKSingleKey.BTN_F, AxiInputEx.ByKeyCode(KeyCode.O));
//Axis
controllers[0].SetKey((ulong)MAMEKSingleKey.UP, AxiInputEx.ByAxis(AxiInputAxisType.UP));
controllers[0].SetKey((ulong)MAMEKSingleKey.DOWN, AxiInputEx.ByAxis(AxiInputAxisType.DOWN));
controllers[0].SetKey((ulong)MAMEKSingleKey.LEFT, AxiInputEx.ByAxis(AxiInputAxisType.LEFT));
controllers[0].SetKey((ulong)MAMEKSingleKey.RIGHT, AxiInputEx.ByAxis(AxiInputAxisType.RIGHT));
//P1 UGUI
controllers[0].SetKey((ulong)MAMEKSingleKey.GAMESTART, AxiInputEx.ByUGUIBtn(AxiInputUGuiBtnType.POTION_1));
controllers[0].SetKey((ulong)MAMEKSingleKey.INSERT_COIN, AxiInputEx.ByUGUIBtn(AxiInputUGuiBtnType.POTION_2));
controllers[0].SetKey((ulong)MAMEKSingleKey.UP, AxiInputEx.ByUGUIBtn(AxiInputUGuiBtnType.UP));
controllers[0].SetKey((ulong)MAMEKSingleKey.DOWN, AxiInputEx.ByUGUIBtn(AxiInputUGuiBtnType.DOWN));
controllers[0].SetKey((ulong)MAMEKSingleKey.LEFT, AxiInputEx.ByUGUIBtn(AxiInputUGuiBtnType.LEFT));
controllers[0].SetKey((ulong)MAMEKSingleKey.RIGHT, AxiInputEx.ByUGUIBtn(AxiInputUGuiBtnType.RIGHT));
controllers[0].SetKey((ulong)MAMEKSingleKey.BTN_A, AxiInputEx.ByUGUIBtn(AxiInputUGuiBtnType.BTN_1));
controllers[0].SetKey((ulong)MAMEKSingleKey.BTN_B, AxiInputEx.ByUGUIBtn(AxiInputUGuiBtnType.BTN_2));
controllers[0].SetKey((ulong)MAMEKSingleKey.BTN_C, AxiInputEx.ByUGUIBtn(AxiInputUGuiBtnType.BTN_3));
controllers[0].SetKey((ulong)MAMEKSingleKey.BTN_D, AxiInputEx.ByUGUIBtn(AxiInputUGuiBtnType.BTN_4));
controllers[0].SetKey((ulong)MAMEKSingleKey.BTN_E, AxiInputEx.ByUGUIBtn(AxiInputUGuiBtnType.BTN_5));
controllers[0].SetKey((ulong)MAMEKSingleKey.BTN_F, AxiInputEx.ByUGUIBtn(AxiInputUGuiBtnType.BTN_6));
controllers[0].ColletAllKey();
#endregion
}
}
public class MAMEKSingleKeysSeting : SingleKeysSetting
{
public enum MAMEKSingleKey
{
INSERT_COIN,
GAMESTART,
UP,
DOWN,
LEFT,
RIGHT,
BTN_A,
BTN_B,
BTN_C,
BTN_D,
BTN_E,
BTN_F
}
Dictionary<MAMEKSingleKey, List<AxiInput>> DictSkey2AxiInput = new Dictionary<MAMEKSingleKey, List<AxiInput>>();
AxiInput[] AxiInputArr = null;
public void SetKey(ulong Key, AxiInput input)
{
List<AxiInput> list;
if (!DictSkey2AxiInput.TryGetValue((MAMEKSingleKey)Key, out list))
list = DictSkey2AxiInput[(MAMEKSingleKey)Key] = ObjectPoolAuto.AcquireList<AxiInput>();
list.Add(input);
}
public bool GetKey(MAMEKSingleKey Key)
{
List<AxiInput> list;
if (!DictSkey2AxiInput.TryGetValue(Key, out list))
return false;
for (int i = 0; i < list.Count; i++)
{
if (list[i].IsKey())
return true;
}
return false;
}
public void ClearAll()
{
foreach (List<AxiInput> singlelist in DictSkey2AxiInput.Values)
ObjectPoolAuto.Release(singlelist);
DictSkey2AxiInput.Clear();
AxiInputArr = null;
}
public void ColletAllKey()
{
List<AxiInput> list = ObjectPoolAuto.AcquireList<AxiInput>();
foreach (List<AxiInput> singlelist in DictSkey2AxiInput.Values)
list.AddRange(singlelist);
AxiInputArr = list.ToArray();
ObjectPoolAuto.Release(list);
}
public bool HadAnyKeyDown()
{
if (AxiInputArr == null)
return false;
for (int i = 0; AxiInputArr.Length > 0; i++)
{
if (AxiInputArr[i].IsKey())
return true;
}
return false;
}
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 5c0bc1cf4f411aa4da3ffa218db2c2aa