From d7269175cd20076bbf054a190cf0a685b88ecee6 Mon Sep 17 00:00:00 2001 From: "ALIENJACK\\alien" Date: Tue, 26 Nov 2024 16:54:51 +0800 Subject: [PATCH] fuck InputSystem! --- .../Assets/Resources/InputSystem.meta | 8 - .../InputSystem/UI_InputSetting.inputactions | 304 ------------------ .../UI_InputSetting.inputactions.meta | 14 - .../Assets/Resources/NES/NesEmulator.prefab | 1 + .../Assets/Scene/AxibugEmuOnline.Client.unity | 95 ------ AxibugEmuOnline.Client/Assets/Script/App.cs | 8 +- .../Assets/Script/IEmuCore.cs | 1 + .../Script/IkeyMapperChanger/GamingChanger.cs | 10 - .../IkeyMapperChanger/GamingChanger.cs.meta | 11 - .../Script/IkeyMapperChanger/NormalChanger.cs | 10 - .../IkeyMapperChanger/NormalChanger.cs.meta | 11 - .../Script/NesEmulator/CoreSupporter.cs | 7 +- .../Script/NesEmulator/NesControllerMapper.cs | 264 +++++++++------ .../Assets/Script/NesEmulator/NesEmulator.cs | 7 +- .../UI/CommandDispatcher/CommandDispatcher.cs | 20 +- .../UI/CommandDispatcher/CommandExcuter.cs | 3 + .../UI/CommandDispatcher/CommandListener.cs | 65 ---- .../CommandDispatcher/CommandListener.cs.meta | 11 - .../Supporter/ControllerState.cs | 1 + AxibugEmuOnline.Client/Packages/manifest.json | 1 - .../Packages/packages-lock.json | 9 - 21 files changed, 188 insertions(+), 673 deletions(-) delete mode 100644 AxibugEmuOnline.Client/Assets/Resources/InputSystem.meta delete mode 100644 AxibugEmuOnline.Client/Assets/Resources/InputSystem/UI_InputSetting.inputactions delete mode 100644 AxibugEmuOnline.Client/Assets/Resources/InputSystem/UI_InputSetting.inputactions.meta delete mode 100644 AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/GamingChanger.cs delete mode 100644 AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/GamingChanger.cs.meta delete mode 100644 AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/NormalChanger.cs delete mode 100644 AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/NormalChanger.cs.meta delete mode 100644 AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandListener.cs delete mode 100644 AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandListener.cs.meta diff --git a/AxibugEmuOnline.Client/Assets/Resources/InputSystem.meta b/AxibugEmuOnline.Client/Assets/Resources/InputSystem.meta deleted file mode 100644 index 3863769..0000000 --- a/AxibugEmuOnline.Client/Assets/Resources/InputSystem.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 6178d336be6488b46aed623405e79f7b -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/AxibugEmuOnline.Client/Assets/Resources/InputSystem/UI_InputSetting.inputactions b/AxibugEmuOnline.Client/Assets/Resources/InputSystem/UI_InputSetting.inputactions deleted file mode 100644 index 5b0afe0..0000000 --- a/AxibugEmuOnline.Client/Assets/Resources/InputSystem/UI_InputSetting.inputactions +++ /dev/null @@ -1,304 +0,0 @@ -{ - "name": "New Controls", - "maps": [ - { - "name": "UI_Normal", - "id": "9a397a4f-4d88-492f-a918-bf9b8d3be756", - "actions": [ - { - "name": "SelectItemLeft", - "type": "Button", - "id": "107019fe-240c-46ff-8c62-cb385ef8b9af", - "expectedControlType": "Button", - "processors": "", - "interactions": "", - "initialStateCheck": false - }, - { - "name": "SelectItemRight", - "type": "Button", - "id": "826dd3f1-2cf8-4169-97c8-dfb56b850143", - "expectedControlType": "Button", - "processors": "", - "interactions": "", - "initialStateCheck": false - }, - { - "name": "SelectItemUp", - "type": "Button", - "id": "505dabb4-91f7-430c-8696-092690269639", - "expectedControlType": "Button", - "processors": "", - "interactions": "", - "initialStateCheck": false - }, - { - "name": "SelectItemDown", - "type": "Button", - "id": "b3da8633-7f50-44b3-8302-50706e589307", - "expectedControlType": "Button", - "processors": "", - "interactions": "", - "initialStateCheck": false - }, - { - "name": "Enter", - "type": "Button", - "id": "0bdf3154-e1db-4044-af50-cacb3764a07c", - "expectedControlType": "Button", - "processors": "", - "interactions": "", - "initialStateCheck": false - }, - { - "name": "Back", - "type": "Button", - "id": "68074d67-61a1-4a4d-bd68-8398b0e7afe3", - "expectedControlType": "Button", - "processors": "", - "interactions": "", - "initialStateCheck": false - }, - { - "name": "OptionMenu", - "type": "Button", - "id": "64b67280-c530-4e38-b3ff-8d0177591396", - "expectedControlType": "Button", - "processors": "", - "interactions": "", - "initialStateCheck": false - } - ], - "bindings": [ - { - "name": "", - "id": "fc724bf2-7736-419c-9f46-19bd45a0d276", - "path": "/a", - "interactions": "", - "processors": "", - "groups": "Keyboard", - "action": "SelectItemLeft", - "isComposite": false, - "isPartOfComposite": false - }, - { - "name": "", - "id": "02f4433e-4417-4fef-b178-a616e2941311", - "path": "/leftArrow", - "interactions": "", - "processors": "", - "groups": "Keyboard", - "action": "SelectItemLeft", - "isComposite": false, - "isPartOfComposite": false - }, - { - "name": "", - "id": "cb874e72-d3db-4024-b9fb-37190acd9568", - "path": "/d", - "interactions": "", - "processors": "", - "groups": "Keyboard", - "action": "SelectItemRight", - "isComposite": false, - "isPartOfComposite": false - }, - { - "name": "", - "id": "646b923b-4d3d-4b5c-9dd2-0119e9d3e2c5", - "path": "/rightArrow", - "interactions": "", - "processors": "", - "groups": "Keyboard", - "action": "SelectItemRight", - "isComposite": false, - "isPartOfComposite": false - }, - { - "name": "", - "id": "28fa0139-d5a2-4e26-87af-2043e01234e6", - "path": "/w", - "interactions": "", - "processors": "", - "groups": "Keyboard", - "action": "SelectItemUp", - "isComposite": false, - "isPartOfComposite": false - }, - { - "name": "", - "id": "4474efdf-70ff-4826-883c-2fdf9f96e78e", - "path": "/upArrow", - "interactions": "", - "processors": "", - "groups": "Keyboard", - "action": "SelectItemUp", - "isComposite": false, - "isPartOfComposite": false - }, - { - "name": "", - "id": "392a8cbc-71f6-4282-b945-4c7b3d17ba3a", - "path": "/s", - "interactions": "", - "processors": "", - "groups": "Keyboard", - "action": "SelectItemDown", - "isComposite": false, - "isPartOfComposite": false - }, - { - "name": "", - "id": "f30b6fb3-147e-4997-b628-fab3f635192b", - "path": "/downArrow", - "interactions": "", - "processors": "", - "groups": "Keyboard", - "action": "SelectItemDown", - "isComposite": false, - "isPartOfComposite": false - }, - { - "name": "", - "id": "70c6db12-432b-482d-99a1-71e002c30157", - "path": "/k", - "interactions": "", - "processors": "", - "groups": "Keyboard", - "action": "Enter", - "isComposite": false, - "isPartOfComposite": false - }, - { - "name": "", - "id": "48d5c450-6ac3-40fb-8ff4-66c7f3b3a00b", - "path": "/enter", - "interactions": "", - "processors": "", - "groups": "Keyboard", - "action": "Enter", - "isComposite": false, - "isPartOfComposite": false - }, - { - "name": "", - "id": "ef83ae7c-a809-4f23-a206-102199a5ede3", - "path": "/l", - "interactions": "", - "processors": "", - "groups": "Keyboard", - "action": "Back", - "isComposite": false, - "isPartOfComposite": false - }, - { - "name": "", - "id": "14b503c8-80a1-458c-9e0f-a3fa38f314be", - "path": "/backspace", - "interactions": "", - "processors": "", - "groups": "Keyboard", - "action": "Back", - "isComposite": false, - "isPartOfComposite": false - }, - { - "name": "", - "id": "e1e12f45-fb41-4b78-adbf-add2881bd4b1", - "path": "/i", - "interactions": "", - "processors": "", - "groups": "Keyboard", - "action": "OptionMenu", - "isComposite": false, - "isPartOfComposite": false - }, - { - "name": "", - "id": "0b010e17-3581-42e6-90b1-f1bf728a3a0c", - "path": "/shift", - "interactions": "", - "processors": "", - "groups": "Keyboard", - "action": "OptionMenu", - "isComposite": false, - "isPartOfComposite": false - } - ] - }, - { - "name": "UI_InGame", - "id": "2c8af03e-03e7-4553-81c6-dcff543cdcdc", - "actions": [ - { - "name": "OptionMenu", - "type": "Button", - "id": "cab3c346-07e2-4c0c-8377-cb934dd28bd3", - "expectedControlType": "Button", - "processors": "", - "interactions": "", - "initialStateCheck": false - } - ], - "bindings": [ - { - "name": "", - "id": "28d4d045-1070-4ea0-be35-b5ffb1c33bcb", - "path": "/escape", - "interactions": "", - "processors": "", - "groups": "Keyboard", - "action": "OptionMenu", - "isComposite": false, - "isPartOfComposite": false - } - ] - } - ], - "controlSchemes": [ - { - "name": "Keyboard", - "bindingGroup": "Keyboard", - "devices": [ - { - "devicePath": "", - "isOptional": false, - "isOR": false - } - ] - }, - { - "name": "UniversalGamePad", - "bindingGroup": "UniversalGamePad", - "devices": [ - { - "devicePath": "", - "isOptional": false, - "isOR": false - } - ] - }, - { - "name": "Xbox Controller", - "bindingGroup": "Xbox Controller", - "devices": [ - { - "devicePath": "", - "isOptional": false, - "isOR": false - } - ] - }, - { - "name": "PlayStation Controller", - "bindingGroup": "PlayStation Controller", - "devices": [ - { - "devicePath": "", - "isOptional": false, - "isOR": false - } - ] - } - ] -} \ No newline at end of file diff --git a/AxibugEmuOnline.Client/Assets/Resources/InputSystem/UI_InputSetting.inputactions.meta b/AxibugEmuOnline.Client/Assets/Resources/InputSystem/UI_InputSetting.inputactions.meta deleted file mode 100644 index e9c5b5a..0000000 --- a/AxibugEmuOnline.Client/Assets/Resources/InputSystem/UI_InputSetting.inputactions.meta +++ /dev/null @@ -1,14 +0,0 @@ -fileFormatVersion: 2 -guid: eb413fd14a8483440af9652b7e4df5e1 -ScriptedImporter: - internalIDToNameTable: [] - externalObjects: {} - serializedVersion: 2 - userData: - assetBundleName: - assetBundleVariant: - script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3} - generateWrapperCode: 0 - wrapperCodePath: - wrapperClassName: - wrapperCodeNamespace: InputSystem diff --git a/AxibugEmuOnline.Client/Assets/Resources/NES/NesEmulator.prefab b/AxibugEmuOnline.Client/Assets/Resources/NES/NesEmulator.prefab index 29b2f60..81baa9f 100644 --- a/AxibugEmuOnline.Client/Assets/Resources/NES/NesEmulator.prefab +++ b/AxibugEmuOnline.Client/Assets/Resources/NES/NesEmulator.prefab @@ -458,6 +458,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 39557e19783acee499ace6c68549e8f8, type: 3} m_Name: m_EditorClassIdentifier: + InputTemplate: {fileID: 0} VideoProvider: {fileID: 4232056520112715744} AudioProvider: {fileID: 9003897287163669553} m_bPause: 0 diff --git a/AxibugEmuOnline.Client/Assets/Scene/AxibugEmuOnline.Client.unity b/AxibugEmuOnline.Client/Assets/Scene/AxibugEmuOnline.Client.unity index d80e2e7..2da0c26 100644 --- a/AxibugEmuOnline.Client/Assets/Scene/AxibugEmuOnline.Client.unity +++ b/AxibugEmuOnline.Client/Assets/Scene/AxibugEmuOnline.Client.unity @@ -13427,7 +13427,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 4471d8231d16ba3469228e09d4cb3a81, type: 3} m_Name: m_EditorClassIdentifier: - LegacyInput: 0 --- !u!4 &1427887270 Transform: m_ObjectHideFlags: 0 @@ -13731,7 +13730,6 @@ RectTransform: m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0, y: 0, z: 0} m_Children: - - {fileID: 2073453794} - {fileID: 1983793178} - {fileID: 246947326} - {fileID: 1318590597} @@ -13832,99 +13830,6 @@ RectTransform: m_CorrespondingSourceObject: {fileID: 1639091784002085428, guid: 450328d5a907c8249a60bc3980ba66f6, type: 3} m_PrefabInstance: {fileID: 730698711} m_PrefabAsset: {fileID: 0} ---- !u!1 &2073453793 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 2073453794} - - component: {fileID: 2073453795} - m_Layer: 0 - m_Name: UI_Input - m_TagString: UIInput - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &2073453794 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2073453793} - m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: -10799.999} - m_LocalScale: {x: 108, y: 108, z: 108} - m_Children: [] - m_Father: {fileID: 1599240741} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &2073453795 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2073453793} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 62899f850307741f2a39c98a8b639597, type: 3} - m_Name: - m_EditorClassIdentifier: - m_Actions: {fileID: -944628639613478452, guid: eb413fd14a8483440af9652b7e4df5e1, type: 3} - m_NotificationBehavior: 3 - m_UIInputModule: {fileID: 74796457} - m_DeviceLostEvent: - m_PersistentCalls: - m_Calls: [] - m_DeviceRegainedEvent: - m_PersistentCalls: - m_Calls: [] - m_ControlsChangedEvent: - m_PersistentCalls: - m_Calls: [] - m_ActionEvents: - - m_PersistentCalls: - m_Calls: [] - m_ActionId: 107019fe-240c-46ff-8c62-cb385ef8b9af - m_ActionName: UI_Normal/SelectItemLeft - - m_PersistentCalls: - m_Calls: [] - m_ActionId: 826dd3f1-2cf8-4169-97c8-dfb56b850143 - m_ActionName: UI_Normal/SelectItemRight - - m_PersistentCalls: - m_Calls: [] - m_ActionId: 505dabb4-91f7-430c-8696-092690269639 - m_ActionName: UI_Normal/SelectItemUp - - m_PersistentCalls: - m_Calls: [] - m_ActionId: b3da8633-7f50-44b3-8302-50706e589307 - m_ActionName: UI_Normal/SelectItemDown - - m_PersistentCalls: - m_Calls: [] - m_ActionId: 0bdf3154-e1db-4044-af50-cacb3764a07c - m_ActionName: UI_Normal/Enter - - m_PersistentCalls: - m_Calls: [] - m_ActionId: 68074d67-61a1-4a4d-bd68-8398b0e7afe3 - m_ActionName: UI_Normal/Back - - m_PersistentCalls: - m_Calls: [] - m_ActionId: 64b67280-c530-4e38-b3ff-8d0177591396 - m_ActionName: UI_Normal/OptionMenu - - m_PersistentCalls: - m_Calls: [] - m_ActionId: cab3c346-07e2-4c0c-8377-cb934dd28bd3 - m_ActionName: UI_InGame/OptionMenu - m_NeverAutoSwitchControlSchemes: 0 - m_DefaultControlScheme: Keyboard - m_DefaultActionMap: UI_Normal - m_SplitScreenIndex: -1 - m_Camera: {fileID: 0} --- !u!1001 &1963501580473600373 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/AxibugEmuOnline.Client/Assets/Script/App.cs b/AxibugEmuOnline.Client/Assets/Script/App.cs index 3afd984..fe55e09 100644 --- a/AxibugEmuOnline.Client/Assets/Script/App.cs +++ b/AxibugEmuOnline.Client/Assets/Script/App.cs @@ -5,7 +5,6 @@ using System.IO; using System.Threading.Tasks; using UnityEngine; using UnityEngine.Networking; -using UnityEngine.Scripting; using static AxibugEmuOnline.Client.HttpAPI; using static AxibugEmuOnline.Client.Manager.LogManager; @@ -38,11 +37,6 @@ namespace AxibugEmuOnline.Client.ClientCore #else public static string PersistentDataPath => Application.persistentDataPath; #endif - - - - //[Preserve] - //[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)] public static void Init() { settings = new AppSettings(); @@ -162,7 +156,7 @@ namespace AxibugEmuOnline.Client.ClientCore } static void OnNoSugarNetLog(int LogLevel, string msg) { - E_LogType logType =(E_LogType)LogLevel; + E_LogType logType = (E_LogType)LogLevel; switch (logType) { case E_LogType.Debug: diff --git a/AxibugEmuOnline.Client/Assets/Script/IEmuCore.cs b/AxibugEmuOnline.Client/Assets/Script/IEmuCore.cs index 68a5df8..694b5e9 100644 --- a/AxibugEmuOnline.Client/Assets/Script/IEmuCore.cs +++ b/AxibugEmuOnline.Client/Assets/Script/IEmuCore.cs @@ -15,6 +15,7 @@ namespace AxibugEmuOnline.Client void SetupScheme(); void StartGame(RomFile romFile); void DoReset(); + EnumPlatform Platform { get; } uint Frame { get; } } diff --git a/AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/GamingChanger.cs b/AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/GamingChanger.cs deleted file mode 100644 index cb62ac5..0000000 --- a/AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/GamingChanger.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace AxibugEmuOnline.Client -{ - public class GamingChanger : CommandChanger - { - public override object GetConfig() - { - return "UI_InGame"; - } - } -} diff --git a/AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/GamingChanger.cs.meta b/AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/GamingChanger.cs.meta deleted file mode 100644 index 9eb3de0..0000000 --- a/AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/GamingChanger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: e5b6687e9412f174d82b2c15f1efc4a4 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/NormalChanger.cs b/AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/NormalChanger.cs deleted file mode 100644 index 7ea16b2..0000000 --- a/AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/NormalChanger.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace AxibugEmuOnline.Client -{ - public class NormalChanger : CommandChanger - { - public override object GetConfig() - { - return "UI_Normal"; - } - } -} diff --git a/AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/NormalChanger.cs.meta b/AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/NormalChanger.cs.meta deleted file mode 100644 index 51b8408..0000000 --- a/AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/NormalChanger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 8aa965a6a15aa1a4195977111b1ec13b -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/CoreSupporter.cs b/AxibugEmuOnline.Client/Assets/Script/NesEmulator/CoreSupporter.cs index bd6fc1d..9dd81d2 100644 --- a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/CoreSupporter.cs +++ b/AxibugEmuOnline.Client/Assets/Script/NesEmulator/CoreSupporter.cs @@ -1,5 +1,4 @@ using AxibugEmuOnline.Client.ClientCore; -using AxiReplay; using System; using System.IO; using System.Runtime.InteropServices; @@ -57,7 +56,7 @@ namespace AxibugEmuOnline.Client } public EmulatorConfig Config { get; private set; } = new EmulatorConfig(); - + public NesControllerMapper ControllerMapper { get; private set; } = new NesControllerMapper(); public void PrepareDirectory(string directPath) { Directory.CreateDirectory($"{App.PersistentDataPath}/{directPath}"); @@ -115,7 +114,7 @@ namespace AxibugEmuOnline.Client } else m_sampledState = default; - var localState = NesControllerMapper.Get().CreateState(); + var localState = ControllerMapper.CreateState(); var rawData = ToNet(localState); if (LastTestInput != rawData) { @@ -126,7 +125,7 @@ namespace AxibugEmuOnline.Client } else { - m_sampledState = NesControllerMapper.Get().CreateState(); + m_sampledState = ControllerMapper.CreateState(); } } diff --git a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesControllerMapper.cs b/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesControllerMapper.cs index 66fb958..3a5df6e 100644 --- a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesControllerMapper.cs +++ b/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesControllerMapper.cs @@ -1,6 +1,5 @@ -using AxibugEmuOnline.Client.ClientCore; -using System; -using System.IO; +using System; +using System.Text; using UnityEngine; using VirtualNes.Core; @@ -8,36 +7,10 @@ namespace AxibugEmuOnline.Client { public class NesControllerMapper { - private static readonly string ConfigFilePath = $"{App.PersistentDataPath}/NES/ControllerMapper.json"; - - public MapperSetter Player1 = new MapperSetter(); - public MapperSetter Player2 = new MapperSetter(); - public MapperSetter Player3 = new MapperSetter(); - public MapperSetter Player4 = new MapperSetter(); - - public NesControllerMapper() - { - Player1.UP.keyCode = KeyCode.W; - Player1.DOWN.keyCode = KeyCode.S; - Player1.LEFT.keyCode = KeyCode.A; - Player1.RIGHT.keyCode = KeyCode.D; - Player1.B.keyCode = KeyCode.J; - Player1.A.keyCode = KeyCode.K; - Player1.SELECT.keyCode = KeyCode.V; - Player1.START.keyCode = KeyCode.B; - - //PC XBOX - //Player1.B.keyCode = Common.PC_XBOXKEY.A; - //Player1.A.keyCode = Common.PC_XBOXKEY.B; - //Player1.SELECT.keyCode = Common.PC_XBOXKEY.ViewBtn; - //Player1.START.keyCode = Common.PC_XBOXKEY.MenuBtn; - } - - public void Save() - { - var jsonStr = JsonUtility.ToJson(this); - File.WriteAllText(ConfigFilePath, jsonStr); - } + public MapperSetter Player1 = new MapperSetter(1); + public MapperSetter Player2 = new MapperSetter(2); + public MapperSetter Player3 = new MapperSetter(3); + public MapperSetter Player4 = new MapperSetter(4); public ControllerState CreateState() { @@ -46,86 +19,189 @@ namespace AxibugEmuOnline.Client var state3 = Player3.GetButtons(); var state4 = Player4.GetButtons(); - return new ControllerState(state1, state2, state3, state4); + var result = new ControllerState(state1, state2, state3, state4); + return result; } - private static NesControllerMapper s_setting; - public static NesControllerMapper Get() - { - if (s_setting == null) - { - try - { - var json = File.ReadAllText($"{App.PersistentDataPath}/Nes/ControllerMapper.json"); - s_setting = JsonUtility.FromJson(json); - } - catch - { - s_setting = new NesControllerMapper(); - } - } - - return s_setting; - } - - [Serializable] public class Mapper { - public EnumButtonType buttonType; - public KeyCode keyCode; + MapperSetter m_setter; + EnumButtonType m_buttonType; + IKeyListener m_keyListener; + int m_controllerIndex => m_setter.ControllerIndex; - public Mapper(EnumButtonType buttonType) + public Mapper(MapperSetter setter, EnumButtonType buttonType) { - this.buttonType = buttonType; + m_setter = setter; + m_buttonType = buttonType; + + loadConfig(); + } + + private void loadConfig() + { + m_keyListener = MapperSetter.GetKey_Legacy(m_controllerIndex, m_buttonType); + + } + + public EnumButtonType SampleKey() + { + return m_keyListener.IsPressing() ? m_buttonType : 0; } } - [Serializable] public class MapperSetter { - public Mapper UP = new Mapper(EnumButtonType.UP); - public Mapper DOWN = new Mapper(EnumButtonType.DOWN); - public Mapper LEFT = new Mapper(EnumButtonType.LEFT); - public Mapper RIGHT = new Mapper(EnumButtonType.RIGHT); - public Mapper A = new Mapper(EnumButtonType.A); - public Mapper B = new Mapper(EnumButtonType.B); - public Mapper SELECT = new Mapper(EnumButtonType.SELECT); - public Mapper START = new Mapper(EnumButtonType.START); - public Mapper MIC = new Mapper(EnumButtonType.MIC); + /// 控制器序号(手柄1,2,3,4) + public int ControllerIndex { get; } + public Mapper UP { get; private set; } + public Mapper DOWN { get; private set; } + public Mapper LEFT { get; private set; } + public Mapper RIGHT { get; private set; } + public Mapper A { get; private set; } + public Mapper B { get; private set; } + public Mapper SELECT { get; private set; } + public Mapper START { get; private set; } + public Mapper MIC { get; private set; } + + public MapperSetter(int controllerIndex) + { + ControllerIndex = controllerIndex; + UP = new Mapper(this, EnumButtonType.UP); + DOWN = new Mapper(this, EnumButtonType.DOWN); + LEFT = new Mapper(this, EnumButtonType.LEFT); + RIGHT = new Mapper(this, EnumButtonType.RIGHT); + A = new Mapper(this, EnumButtonType.A); + B = new Mapper(this, EnumButtonType.B); + SELECT = new Mapper(this, EnumButtonType.SELECT); + START = new Mapper(this, EnumButtonType.START); + MIC = new Mapper(this, EnumButtonType.MIC); + } public EnumButtonType GetButtons() { EnumButtonType res = 0; - if (Input.GetKey(UP.keyCode)) - res |= EnumButtonType.UP; - - if (Input.GetKey(DOWN.keyCode)) - res |= EnumButtonType.DOWN; - - if (Input.GetKey(LEFT.keyCode)) - res |= EnumButtonType.LEFT; - - if (Input.GetKey(RIGHT.keyCode)) - res |= EnumButtonType.RIGHT; - - if (Input.GetKey(A.keyCode)) - res |= EnumButtonType.A; - - if (Input.GetKey(B.keyCode)) - res |= EnumButtonType.B; - - if (Input.GetKey(SELECT.keyCode)) - res |= EnumButtonType.SELECT; - - if (Input.GetKey(START.keyCode)) - res |= EnumButtonType.START; - - if (Input.GetKey(MIC.keyCode)) - res |= EnumButtonType.MIC; + res |= UP.SampleKey(); + res |= DOWN.SampleKey(); + res |= LEFT.SampleKey(); + res |= RIGHT.SampleKey(); + res |= A.SampleKey(); + res |= B.SampleKey(); + res |= SELECT.SampleKey(); + res |= START.SampleKey(); + res |= MIC.SampleKey(); return res; } + + public static IKeyListener GetKey_Legacy(int controllerInput, EnumButtonType nesConBtnType) + { + string configKey = $"NES_{controllerInput}_{nesConBtnType}"; + + if (PlayerPrefs.HasKey(configKey)) + { + return new KeyListener_Legacy(PlayerPrefs.GetString(configKey)); + } + else + { + var defaultKeyCode = GetDefaultKey(); + PlayerPrefs.SetString(configKey, defaultKeyCode.ToString()); + return defaultKeyCode; + } + + KeyListener_Legacy GetDefaultKey() + { + switch (controllerInput) + { + case 1: + if (nesConBtnType == EnumButtonType.LEFT) return new KeyListener_Legacy(KeyCode.A, KeyCode.Joystick1Button12); + if (nesConBtnType == EnumButtonType.RIGHT) return new KeyListener_Legacy(KeyCode.D, KeyCode.Joystick1Button13); + if (nesConBtnType == EnumButtonType.UP) return new KeyListener_Legacy(KeyCode.W, KeyCode.Joystick1Button10); + if (nesConBtnType == EnumButtonType.DOWN) return new KeyListener_Legacy(KeyCode.S, KeyCode.Joystick1Button11); + if (nesConBtnType == EnumButtonType.START) return new KeyListener_Legacy(KeyCode.B, KeyCode.Joystick1Button7); + if (nesConBtnType == EnumButtonType.SELECT) return new KeyListener_Legacy(KeyCode.V, KeyCode.Joystick1Button6); + if (nesConBtnType == EnumButtonType.A) return new KeyListener_Legacy(KeyCode.K, KeyCode.Joystick1Button1); + if (nesConBtnType == EnumButtonType.B) return new KeyListener_Legacy(KeyCode.J, KeyCode.Joystick1Button2); + if (nesConBtnType == EnumButtonType.MIC) return new KeyListener_Legacy(KeyCode.M, KeyCode.Joystick1Button12); + break; + case 2: + if (nesConBtnType == EnumButtonType.LEFT) return new KeyListener_Legacy(KeyCode.Delete, KeyCode.Joystick2Button12); + if (nesConBtnType == EnumButtonType.RIGHT) return new KeyListener_Legacy(KeyCode.PageDown, KeyCode.Joystick2Button13); + if (nesConBtnType == EnumButtonType.UP) return new KeyListener_Legacy(KeyCode.Home, KeyCode.Joystick2Button10); + if (nesConBtnType == EnumButtonType.DOWN) return new KeyListener_Legacy(KeyCode.End, KeyCode.Joystick2Button11); + if (nesConBtnType == EnumButtonType.START) return new KeyListener_Legacy(KeyCode.PageUp, KeyCode.Joystick2Button7); + if (nesConBtnType == EnumButtonType.SELECT) return new KeyListener_Legacy(KeyCode.Insert, KeyCode.Joystick2Button6); + if (nesConBtnType == EnumButtonType.A) return new KeyListener_Legacy(KeyCode.Keypad5, KeyCode.Joystick2Button1); + if (nesConBtnType == EnumButtonType.B) return new KeyListener_Legacy(KeyCode.Keypad4, KeyCode.Joystick2Button2); + if (nesConBtnType == EnumButtonType.MIC) return new KeyListener_Legacy(KeyCode.KeypadPeriod, KeyCode.Joystick2Button12); + break; + } + + return default; + } + + } + } + + public interface IKeyListener + { + bool IsPressing(); + } + + public struct KeyListener_Legacy : IKeyListener + { + private KeyCode[] m_keys; + + public KeyListener_Legacy(params KeyCode[] keys) + { + m_keys = keys; + } + + /// + /// 从配置表字符串构建 + /// + /// 以:分割的键值字符串 + public KeyListener_Legacy(string confStr) + { + m_keys = new KeyCode[2]; + + var temp = confStr.Split(':'); + m_keys = new KeyCode[temp.Length]; + for (int i = 0; i < temp.Length; i++) + { + if (int.TryParse(temp[i], out int result)) + m_keys[i] = (KeyCode)result; + } + } + + public bool IsPressing() + { + if (m_keys == null || m_keys.Length == 0) return false; + + foreach (var key in m_keys) + { + if (Input.GetKey(key)) return true; + } + + return false; + } + + public override string ToString() + { + if (m_keys == null || m_keys.Length == 0) return string.Empty; + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < m_keys.Length; i++) + { + var keyVal = (int)m_keys[i]; + sb.Append(keyVal); + if (i != m_keys.Length - 1) sb.Append(':'); + } + + return sb.ToString(); + } } } + + } diff --git a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.cs b/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.cs index 20c7910..fa78912 100644 --- a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.cs +++ b/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.cs @@ -1,5 +1,4 @@ using AxibugEmuOnline.Client.ClientCore; -using AxibugEmuOnline.Client.Common; using System; using System.Diagnostics; using System.IO; @@ -12,6 +11,8 @@ namespace AxibugEmuOnline.Client { public class NesEmulator : MonoBehaviour, IEmuCore { + public EnumPlatform Platform => EnumPlatform.NES; + //ģʵ public NES NesCore { get; private set; } @@ -168,6 +169,8 @@ namespace AxibugEmuOnline.Client NesCore.LoadState(st); } + public uint Frame => NesCore.FrameCount; + #if UNITY_EDITOR /// /// ༭ @@ -197,7 +200,5 @@ namespace AxibugEmuOnline.Client UnityEditor.AssetDatabase.SaveAssets(); } #endif - - public uint Frame => NesCore.FrameCount; } } diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandDispatcher.cs b/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandDispatcher.cs index a9b0c34..1e651cc 100644 --- a/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandDispatcher.cs +++ b/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandDispatcher.cs @@ -1,3 +1,4 @@ +using AxibugEmuOnline.Client.ClientCore; using System.Collections.Generic; using UnityEngine; @@ -18,8 +19,6 @@ namespace AxibugEmuOnline.Client /// ϷUI public IKeyMapperChanger Gaming { get; private set; } - public bool LegacyInput; - private IKeyMapperChanger m_current; public IKeyMapperChanger Current { @@ -37,22 +36,11 @@ namespace AxibugEmuOnline.Client Instance = this; //ʼcommand - if (LegacyInput) - m_listener = new CommandListener_Legacy(); - else - m_listener = new CommandListener(); + m_listener = new CommandListener_Legacy(); //ʼλ޸ - if (LegacyInput) - { - Normal = new NormalChanger_Legacy(); - Gaming = new GamingChanger_Legacy(); - } - else - { - Normal = new NormalChanger(); - Gaming = new GamingChanger(); - } + Normal = new NormalChanger_Legacy(); + Gaming = new GamingChanger_Legacy(); } private void OnDestroy() diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandExcuter.cs b/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandExcuter.cs index 68f1825..992f95e 100644 --- a/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandExcuter.cs +++ b/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandExcuter.cs @@ -49,6 +49,8 @@ namespace AxibugEmuOnline.Client public void ExecuteCommand(EnumCommand cmd, bool cancel) { + if(cmd == EnumCommand.NONE) return; + if (!cancel) { switch (cmd) @@ -118,6 +120,7 @@ namespace AxibugEmuOnline.Client public enum EnumCommand { + NONE, SelectItemLeft, SelectItemRight, SelectItemUp, diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandListener.cs b/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandListener.cs deleted file mode 100644 index e7ee8dd..0000000 --- a/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandListener.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.InputSystem; - -namespace AxibugEmuOnline.Client -{ - public class CommandListener : ICommandListener - { - private PlayerInput m_uiInput; - private IEnumerable m_executers; - - public CommandListener() - { - m_uiInput = GameObject.FindGameObjectWithTag("UIInput").GetComponent(); - m_uiInput.onActionTriggered += M_uiInput_onActionTriggered; - } - public void Update(IEnumerable executer) - { - m_executers = executer; - } - - private void M_uiInput_onActionTriggered(InputAction.CallbackContext obj) - { - CommandState? cs = null; - switch (obj.action.phase) - { - case InputActionPhase.Started: - cs = new CommandState { Cancel = false, Cmd = ToCommandEnum(obj.action.name) }; - break; - case InputActionPhase.Canceled: - cs = new CommandState { Cancel = true, Cmd = ToCommandEnum(obj.action.name) }; - break; - } - if (!cs.HasValue) return; - - foreach (var exec in m_executers) - { - if (!exec.Enable) continue; - exec.ExecuteCommand(cs.Value.Cmd, cs.Value.Cancel); - } - } - - public void ApplyKeyMapper(IKeyMapperChanger changer) - { - var actionMapName = (string)changer.GetConfig(); - m_uiInput.SwitchCurrentActionMap(actionMapName); - } - - EnumCommand ToCommandEnum(string actionName) - { - return actionName switch - { - "SelectItemLeft" => EnumCommand.SelectItemLeft, - "SelectItemRight" => EnumCommand.SelectItemRight, - "SelectItemUp" => EnumCommand.SelectItemUp, - "SelectItemDown" => EnumCommand.SelectItemDown, - "Enter" => EnumCommand.Enter, - "Back" => EnumCommand.Back, - "OptionMenu" => EnumCommand.OptionMenu, - _ => throw new Exception("Not Support Action") - }; - } - } -} diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandListener.cs.meta b/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandListener.cs.meta deleted file mode 100644 index 9827944..0000000 --- a/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandListener.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: a493da4af70f32a43b3c558d94cf23a4 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/ControllerState.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/ControllerState.cs index 352e192..d5e04fa 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/ControllerState.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/ControllerState.cs @@ -60,6 +60,7 @@ namespace VirtualNes.Core [Flags] public enum EnumButtonType { + NONE = 0, UP = 1, DOWN = 2, LEFT = 4, diff --git a/AxibugEmuOnline.Client/Packages/manifest.json b/AxibugEmuOnline.Client/Packages/manifest.json index b63e2fc..165b981 100644 --- a/AxibugEmuOnline.Client/Packages/manifest.json +++ b/AxibugEmuOnline.Client/Packages/manifest.json @@ -2,7 +2,6 @@ "dependencies": { "com.unity.2d.sprite": "1.0.0", "com.unity.ide.visualstudio": "2.0.22", - "com.unity.inputsystem": "1.3.0", "com.unity.postprocessing": "3.2.2", "com.unity.ugui": "1.0.0", "com.unity.modules.ai": "1.0.0", diff --git a/AxibugEmuOnline.Client/Packages/packages-lock.json b/AxibugEmuOnline.Client/Packages/packages-lock.json index 5ab3c71..8bb04f0 100644 --- a/AxibugEmuOnline.Client/Packages/packages-lock.json +++ b/AxibugEmuOnline.Client/Packages/packages-lock.json @@ -22,15 +22,6 @@ }, "url": "https://packages.unity.cn" }, - "com.unity.inputsystem": { - "version": "1.3.0", - "depth": 0, - "source": "registry", - "dependencies": { - "com.unity.modules.uielements": "1.0.0" - }, - "url": "https://packages.unity.cn" - }, "com.unity.postprocessing": { "version": "3.2.2", "depth": 0,