From b8c116aa287f2d123fbbd94e91133b046b524196 Mon Sep 17 00:00:00 2001 From: "ALIENJACK\\alien" Date: Tue, 6 Aug 2024 18:52:11 +0800 Subject: [PATCH] =?UTF-8?q?=E9=94=AE=E4=BD=8D=E9=85=8D=E7=BD=AE=E6=8C=81?= =?UTF-8?q?=E4=B9=85=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Resources/NES/ControlSettings.asset | 126 ------------------ .../Resources/NES/ControlSettings.asset.meta | 8 -- .../Script/NesEmulator/CoreSupporter.cs | 2 +- .../Script/NesEmulator/NesControllerMapper.cs | 42 +++++- 4 files changed, 42 insertions(+), 136 deletions(-) delete mode 100644 AxibugEmuOnline.Client/Assets/Resources/NES/ControlSettings.asset delete mode 100644 AxibugEmuOnline.Client/Assets/Resources/NES/ControlSettings.asset.meta diff --git a/AxibugEmuOnline.Client/Assets/Resources/NES/ControlSettings.asset b/AxibugEmuOnline.Client/Assets/Resources/NES/ControlSettings.asset deleted file mode 100644 index d2b65d7..0000000 --- a/AxibugEmuOnline.Client/Assets/Resources/NES/ControlSettings.asset +++ /dev/null @@ -1,126 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!114 &11400000 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 66fc8233a79cd254f8d005452dcd4ac0, type: 3} - m_Name: ControlSettings - m_EditorClassIdentifier: - Player1: - UP: - buttonType: 1 - keyCode: 119 - DOWN: - buttonType: 2 - keyCode: 115 - LEFT: - buttonType: 4 - keyCode: 97 - RIGHT: - buttonType: 8 - keyCode: 100 - A: - buttonType: 16 - keyCode: 107 - B: - buttonType: 32 - keyCode: 106 - SELECT: - buttonType: 64 - keyCode: 118 - START: - buttonType: 128 - keyCode: 98 - MIC: - buttonType: 256 - keyCode: 0 - Player2: - UP: - buttonType: 1 - keyCode: 0 - DOWN: - buttonType: 2 - keyCode: 0 - LEFT: - buttonType: 4 - keyCode: 0 - RIGHT: - buttonType: 8 - keyCode: 0 - A: - buttonType: 16 - keyCode: 0 - B: - buttonType: 32 - keyCode: 0 - SELECT: - buttonType: 64 - keyCode: 0 - START: - buttonType: 128 - keyCode: 0 - MIC: - buttonType: 256 - keyCode: 0 - Player3: - UP: - buttonType: 1 - keyCode: 0 - DOWN: - buttonType: 2 - keyCode: 0 - LEFT: - buttonType: 4 - keyCode: 0 - RIGHT: - buttonType: 8 - keyCode: 0 - A: - buttonType: 16 - keyCode: 0 - B: - buttonType: 32 - keyCode: 0 - SELECT: - buttonType: 64 - keyCode: 0 - START: - buttonType: 128 - keyCode: 0 - MIC: - buttonType: 256 - keyCode: 0 - Player4: - UP: - buttonType: 1 - keyCode: 0 - DOWN: - buttonType: 2 - keyCode: 0 - LEFT: - buttonType: 4 - keyCode: 0 - RIGHT: - buttonType: 8 - keyCode: 0 - A: - buttonType: 16 - keyCode: 0 - B: - buttonType: 32 - keyCode: 0 - SELECT: - buttonType: 64 - keyCode: 0 - START: - buttonType: 128 - keyCode: 0 - MIC: - buttonType: 256 - keyCode: 0 diff --git a/AxibugEmuOnline.Client/Assets/Resources/NES/ControlSettings.asset.meta b/AxibugEmuOnline.Client/Assets/Resources/NES/ControlSettings.asset.meta deleted file mode 100644 index 60582ad..0000000 --- a/AxibugEmuOnline.Client/Assets/Resources/NES/ControlSettings.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: fa3a6bfd9566da84eb494ff280abe34c -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 11400000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/CoreSupporter.cs b/AxibugEmuOnline.Client/Assets/Script/NesEmulator/CoreSupporter.cs index 68e7e8c..ae766d6 100644 --- a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/CoreSupporter.cs +++ b/AxibugEmuOnline.Client/Assets/Script/NesEmulator/CoreSupporter.cs @@ -101,7 +101,7 @@ namespace AxibugEmuOnline.Client public ControllerState GetControllerState() { - var mapper = Resources.Load("NES/ControlSettings"); + var mapper = NesControllerMapper.Get(); return mapper.CreateState(); } } diff --git a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesControllerMapper.cs b/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesControllerMapper.cs index 82ebec0..c9ab5f6 100644 --- a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesControllerMapper.cs +++ b/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesControllerMapper.cs @@ -1,16 +1,37 @@ using System; +using System.IO; using UnityEngine; using VirtualNes.Core; namespace AxibugEmuOnline.Client { - public class NesControllerMapper : ScriptableObject + public class NesControllerMapper { + private static readonly string ConfigFilePath = $"{Application.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; + } + + public void Save() + { + var jsonStr = JsonUtility.ToJson(this); + File.WriteAllText(ConfigFilePath, jsonStr); + } + public ControllerState CreateState() { var state1 = Player1.GetButtons(); @@ -21,6 +42,25 @@ namespace AxibugEmuOnline.Client return new ControllerState(state1, state2, state3, state4); } + private static NesControllerMapper s_setting; + public static NesControllerMapper Get() + { + if (s_setting == null) + { + try + { + var json = File.ReadAllText($"{Application.persistentDataPath}/Nes/ControllerMapper.json"); + s_setting = JsonUtility.FromJson(json); + } + catch + { + s_setting = new NesControllerMapper(); + } + } + + return s_setting; + } + [Serializable] public class Mapper {