即时存档功能和Replay功能

This commit is contained in:
sin365 2024-08-30 17:33:22 +08:00
parent 697fb8f63b
commit bac00afcdc
18 changed files with 1318 additions and 389 deletions

Binary file not shown.

View File

@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: 03ba7721c0d6ddf48bb3d6575497a990
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 1
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: fae13461b22160c47b5ee9964058b719
guid: 111763684b017184c8de7d0d4efbfeb1
PluginImporter:
externalObjects: {}
serializedVersion: 2

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@ -0,0 +1,96 @@
fileFormatVersion: 2
guid: d3ccc3158bc938e4caa62373c8ee3b78
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,35 +1,33 @@
using UnityEngine;
namespace Assets.Script.UMAME.Common
public class UniMAMESetting
{
public class UniMAMESetting
public static UniMAMESetting instance
{
public static UniMAMESetting instance
get
{
get
{
if (mInstance == null)
mInstance = new UniMAMESetting();
return mInstance;
}
if (mInstance == null)
mInstance = new UniMAMESetting();
return mInstance;
}
private static UniMAMESetting mInstance;
const string KEY_LASTGAMEROM = "MAME_LASTGAMEROM";
public string LastGameRom
{
get
{
if(PlayerPrefs.HasKey(KEY_LASTGAMEROM))
return PlayerPrefs.GetString(KEY_LASTGAMEROM);
return string.Empty;
}
set
{
PlayerPrefs.SetString(KEY_LASTGAMEROM, value);
}
}
}
}
private static UniMAMESetting mInstance;
const string KEY_LASTGAMEROM = "MAME_LASTGAMEROM";
public string LastGameRom
{
get
{
if (PlayerPrefs.HasKey(KEY_LASTGAMEROM))
return PlayerPrefs.GetString(KEY_LASTGAMEROM);
return string.Empty;
}
set
{
PlayerPrefs.SetString(KEY_LASTGAMEROM, value);
}
}
}

View File

@ -1,11 +1,11 @@
using MAME.Core.run_interface;
using MAME.Core;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class UILongClickButton : Button
{
public bool bHotKey { get; private set; } = false;
public MotionKey[] Key;
public long[] Key;
protected override void OnEnable()
{
base.OnEnable();

View File

@ -1,31 +1,39 @@
using Assets.Script.UMAME.Common;
using mame;
using MAME.Core.Motion;
using AxiReplay;
using MAME.Core;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine.UI;
public class UMAME : MonoBehaviour
{
MameMainMotion emu;
public static UMAME instance { get; private set; }
MAMEEmu emu;
UniLog mUniLog;
UniMouse mUniMouse;
UniVideoPlayer mUniVideoPlayer;
[HideInInspector]
public UniVideoPlayer mUniVideoPlayer;
UniSoundPlayer mUniSoundPlayer;
UniKeyboard mUniKeyboard;
UniResources mUniResources;
public Text mFPS;
public Button btnStop;
public Button btnStart;
public Button btnRePlay;
public Button btnRePayySave;
public Button btnRomDir;
public Button btnSaveState;
public Button btnLoadState;
public Dictionary<string, RomInfo> ALLGame;
public List<RomInfo> HadGameList = new List<RomInfo>();
string mChangeRomName = string.Empty;
public bool bQuickTestRom = false;
public string mQuickTestRom = string.Empty;
public ReplayWriter mReplayWriter;
public ReplayReader mReplayReader;
Dropdown optionDropdown;
@ -34,20 +42,27 @@ public class UMAME : MonoBehaviour
#if UNITY_EDITOR_WIN
public static string RomPath => "G:\\MAME.NET.Rom";
public static string EmuDataPath => "G:/MAME.Core";
#elif UNITY_ANDROID
public static string RomPath => Application.persistentDataPath;
public static string EmuDataPath => Application.persistentDataPath;
#elif UNITY_PSP2
public static string RomPath => Application.dataPath;
public static string EmuDataPath => Application.dataPath;
#else
public static string RomPath => Application.persistentDataPath;
public static string EmuDataPath => Application.persistentDataPath;
#endif
public static string RomPath => EmuDataPath + "/roms/";
public static string SavePath => EmuDataPath + "/sav/";
private void Awake()
{
// Ç¿ÖƺáÆÁ
Screen.orientation = ScreenOrientation.LandscapeLeft;
instance = this;
mFPS = GameObject.Find("FPS").GetComponent<Text>();
optionDropdown = GameObject.Find("optionDropdown").GetComponent<Dropdown>();
emu = new MameMainMotion();
emu = new MAMEEmu();
mUniLog = new UniLog();
mUniMouse = this.gameObject.AddComponent<UniMouse>();
mUniVideoPlayer = this.gameObject.AddComponent<UniVideoPlayer>();
@ -56,7 +71,7 @@ public class UMAME : MonoBehaviour
mUniResources = new UniResources();
mChangeRomName = UniMAMESetting.instance.LastGameRom;
emu.Init(RomPath, mUniLog, mUniResources, mUniVideoPlayer, mUniSoundPlayer, mUniKeyboard, mUniMouse);
emu.Init(RomPath, mUniLog, mUniResources, mUniVideoPlayer, mUniSoundPlayer, mUniKeyboard.mKeyCodeCore, mUniMouse);
ALLGame = emu.GetGameList();
Debug.Log($"ALLGame:{ALLGame.Count}");
@ -77,11 +92,21 @@ public class UMAME : MonoBehaviour
void OnEnable()
{
btnStop.onClick.AddListener(StopGame);
btnStart.onClick.AddListener(LoadGame);
btnStart.onClick.AddListener(() => { LoadGame(false); });
btnRePlay.onClick.AddListener(() => { LoadGame(true); });
btnRePayySave.onClick.AddListener(() => SaveReplay());
btnSaveState.onClick.AddListener(SaveState);
btnLoadState.onClick.AddListener(LoadState);
}
void LoadGame()
void OnDisable()
{
StopGame();
}
void LoadGame(bool bReplay = false)
{
mReplayWriter = new ReplayWriter(mChangeRomName, "fuck", ReplayData.ReplayFormat.FM32IP64, Encoding.UTF8);
mChangeRomName = HadGameList[optionDropdown.value].Name;
UniMAMESetting.instance.LastGameRom = mChangeRomName;
StopGame();
@ -90,6 +115,13 @@ public class UMAME : MonoBehaviour
//读取成功
if (emu.bRom)
{
if (bReplay)
{
string Path = SavePath + Machine.sName + ".rp";
mReplayReader = new ReplayReader(Path);
mUniKeyboard.mKeyCodeCore.SetRePlay(true);
}
//读取ROM之后获得宽高初始化画面
emu.GetGameScreenSize(out int _width, out int _height, out IntPtr _framePtr);
Debug.Log($"_width->{_width}, _height->{_height}, _framePtr->{_framePtr}");
@ -108,6 +140,26 @@ public class UMAME : MonoBehaviour
private void Update()
{
mFPS.text = ($"fpsv {mUniVideoPlayer.videoFPS.ToString("F2")} fpsa {mUniSoundPlayer.audioFPS.ToString("F2")}");
if (Input.GetKeyDown(KeyCode.F1))
{
SaveReplay();
}
if (Input.GetKeyDown(KeyCode.F2))
{
string Path = SavePath + Machine.sName + ".rp";
string dbgPath = SavePath + Machine.sName + ".rpread";
mReplayReader = new ReplayReader(Path, true, dbgPath);
mUniKeyboard.mKeyCodeCore.Init(mUniKeyboard, true);
}
}
void SaveReplay()
{
string Path = SavePath + Machine.sName + ".rp";
string dbgPath = SavePath + Machine.sName + ".rpwrite";
mReplayWriter.SaveData(Path, true, dbgPath);
}
void StopGame()
@ -126,14 +178,14 @@ public class UMAME : MonoBehaviour
HadGameList.Clear();
optionDropdown.options.Clear();
Debug.Log($"GetHadRomList:{RomPath + "/roms/"}");
string[] directoryEntries = Directory.GetDirectories(RomPath + "/roms/");
Debug.Log($"GetHadRomList:{RomPath}");
string[] directoryEntries = Directory.GetDirectories(RomPath);
for (int i = 0; i < directoryEntries.Length; i++)
{
string path = directoryEntries[i];
string dirName = Path.GetFileName(path);
if (ALLGame.ContainsKey(dirName))
{
{
HadGameList.Add(ALLGame[dirName]);
optionDropdown.options.Add(new Dropdown.OptionData(dirName));
}
@ -156,4 +208,37 @@ public class UMAME : MonoBehaviour
{
System.Diagnostics.Process.Start("explorer.exe", "/select," + RomPath);
}
void SaveState()
{
if (!Directory.Exists(SavePath))
Directory.CreateDirectory(SavePath);
FileStream fs = new FileStream(SavePath + Machine.sName + ".sta", FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs);
emu.SaveState(bw);
bw.Close();
fs.Close();
byte[] screenData = UMAME.instance.mUniVideoPlayer.GetScreenImg();
FileStream fsImg = new FileStream(SavePath + Machine.sName + ".jpg", FileMode.Create);
fsImg.Write(screenData, 0, screenData.Length);
fsImg.Close();
}
void LoadState()
{
string Path = SavePath + Machine.sName + ".sta";
if (!File.Exists(Path))
{
Debug.Log($"Îļþ²»´æÔÚ{Path}");
return;
}
FileStream fs = new FileStream(Path, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
emu.LoadState(br);
br.Close();
fs.Close();
}
}

View File

@ -0,0 +1,164 @@
using AxiReplay;
using MAME.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;
using UnityEngine;
public class KeyCodeCore : IKeyboard
{
public Dictionary<KeyCode, MotionKey> dictKeyCfgs = new Dictionary<KeyCode, MotionKey>();
public KeyCode[] CheckList;
public MotionKey[] mCurrKey = new MotionKey[0];
public ulong CurryInpuAllData = 0;
List<MotionKey> temp = new List<MotionKey>();
ulong tempInputAllData = 0;
UniKeyboard mUniKeyboard;
bool bReplayMode;
List<MotionKey> ReplayCheckKey = new List<MotionKey>();
public MotionKey[] GetPressedKeys()
{
if (!bReplayMode)
{
//UMAME.instance.mReplayWriter.NextFrame(CurryInpuAllData);
UMAME.instance.mReplayWriter.NextFramebyFrameIdx((int)UMAME.instance.mUniVideoPlayer.mFrame, CurryInpuAllData);
return mCurrKey;
}
else
{
//有变化
//if (UMAME.instance.mReplayReader.NextFrame(out AxiReplay.ReplayStep stepData))
if (UMAME.instance.mReplayReader.NextFramebyFrameIdx((int)UMAME.instance.mUniVideoPlayer.mFrame, out AxiReplay.ReplayStep stepData))
{
temp.Clear();
//有数据
for (int i = 0; i < ReplayCheckKey.Count; i++)
{
if ((stepData.InPut & (ulong)ReplayCheckKey[i]) > 0)
temp.Add(ReplayCheckKey[i]);
}
mCurrKey = temp.ToArray();
}
#if UNITY_EDITOR
string TempStr = "";
foreach (var item in mCurrKey)
{
TempStr += $"{item.ToString()}|";
}
if (!string.IsNullOrEmpty(TempStr))
Debug.Log($"Input-》{CurryInpuAllData} => {TempStr}");
#endif
return mCurrKey;
}
}
public void SetRePlay(bool IsReplay)
{
bReplayMode = IsReplay;
}
public void Init(UniKeyboard uniKeyboard, bool IsReplay)
{
bReplayMode = IsReplay;
mUniKeyboard = uniKeyboard;
foreach (MotionKey mkey in Enum.GetValues(typeof(MotionKey)))
{
ReplayCheckKey.Add(mkey);
}
dictKeyCfgs.Clear();
dictKeyCfgs.Add(KeyCode.P, MotionKey.EMU_PAUSED);
dictKeyCfgs.Add(KeyCode.Alpha1, MotionKey.P1_GAMESTART);
dictKeyCfgs.Add(KeyCode.Alpha5, MotionKey.P1_INSERT_COIN);
dictKeyCfgs.Add(KeyCode.W, MotionKey.P1_UP);
dictKeyCfgs.Add(KeyCode.S, MotionKey.P1_DOWN);
dictKeyCfgs.Add(KeyCode.A, MotionKey.P1_LEFT);
dictKeyCfgs.Add(KeyCode.D, MotionKey.P1_RIGHT);
dictKeyCfgs.Add(KeyCode.J, MotionKey.P1_BTN_1);
dictKeyCfgs.Add(KeyCode.K, MotionKey.P1_BTN_2);
dictKeyCfgs.Add(KeyCode.L, MotionKey.P1_BTN_3);
dictKeyCfgs.Add(KeyCode.U, MotionKey.P1_BTN_4);
dictKeyCfgs.Add(KeyCode.KeypadDivide, MotionKey.P2_GAMESTART);
dictKeyCfgs.Add(KeyCode.KeypadMultiply, MotionKey.P2_INSERT_COIN);
dictKeyCfgs.Add(KeyCode.UpArrow, MotionKey.P2_UP);
dictKeyCfgs.Add(KeyCode.DownArrow, MotionKey.P2_DOWN);
dictKeyCfgs.Add(KeyCode.LeftArrow, MotionKey.P2_LEFT);
dictKeyCfgs.Add(KeyCode.RightArrow, MotionKey.P2_RIGHT);
dictKeyCfgs.Add(KeyCode.Keypad1, MotionKey.P2_BTN_1);
dictKeyCfgs.Add(KeyCode.Keypad2, MotionKey.P2_BTN_2);
dictKeyCfgs.Add(KeyCode.Keypad3, MotionKey.P2_BTN_3);
dictKeyCfgs.Add(KeyCode.Keypad4, MotionKey.P2_BTN_4);
CheckList = dictKeyCfgs.Keys.ToArray();
mUniKeyboard.btnP1.Key = new long[] { (long)MotionKey.P1_GAMESTART };
mUniKeyboard.btnCoin1.Key = new long[] { (long)MotionKey.P1_INSERT_COIN };
mUniKeyboard.btnA.Key = new long[] { (long)MotionKey.P1_BTN_1 };
mUniKeyboard.btnB.Key = new long[] { (long)MotionKey.P1_BTN_2 };
mUniKeyboard.btnC.Key = new long[] { (long)MotionKey.P1_BTN_3 };
mUniKeyboard.btnD.Key = new long[] { (long)MotionKey.P1_BTN_4 };
//mUniKeyboard.btnE.Key = new long[] { (long)MotionKey.P1_BTN_5 };
//mUniKeyboard.btnF.Key = new long[] { (long)MotionKey.P1_BTN_6 };
mUniKeyboard.btnAB.Key = new long[] { (long)MotionKey.P1_BTN_1, (long)MotionKey.P1_BTN_2 };
mUniKeyboard.btnCD.Key = new long[] { (long)MotionKey.P1_BTN_3, (long)MotionKey.P1_BTN_4 };
mUniKeyboard.btnABC.Key = new long[] { (long)MotionKey.P1_BTN_1, (long)MotionKey.P1_BTN_2, (long)MotionKey.P1_BTN_3 };
}
public void UpdateLogic()
{
if (bReplayMode) return;
tempInputAllData = 0;
temp.Clear();
for (int i = 0; i < CheckList.Length; i++)
{
if (Input.GetKey(CheckList[i]))
{
MotionKey mk = dictKeyCfgs[CheckList[i]];
temp.Add(mk);
tempInputAllData |= (ulong)mk;
}
}
for (int i = 0; i < mUniKeyboard.mUIBtns.Count; i++)
{
if (mUniKeyboard.mUIBtns[i].bHotKey)
{
for (int j = 0; j < mUniKeyboard.mUIBtns[i].Key.Length; j++)
{
MotionKey mk = (MotionKey)mUniKeyboard.mUIBtns[i].Key[j];
temp.Add(mk);
tempInputAllData |= (ulong)mk;
}
}
}
Vector2Int inputV2 = mUniKeyboard.mJoystick.RawInputV2;
//Debug.Log($"{inputV2.x},{inputV2.y}");
if (inputV2.x > 0)
{
temp.Add(MotionKey.P1_RIGHT);
tempInputAllData |= (ulong)MotionKey.P1_RIGHT;
}
else if (inputV2.x < 0)
{
temp.Add(MotionKey.P1_LEFT);
tempInputAllData |= (ulong)MotionKey.P1_LEFT;
}
if (inputV2.y > 0)
{
temp.Add(MotionKey.P1_UP);
tempInputAllData |= (ulong)MotionKey.P1_UP;
}
else if (inputV2.y < 0)
{
temp.Add(MotionKey.P1_DOWN);
tempInputAllData |= (ulong)MotionKey.P1_DOWN;
}
CurryInpuAllData = tempInputAllData;
mCurrKey = temp.ToArray();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3054336185b15f84d9543bdafb49907f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,15 +1,9 @@
using MAME.Core.run_interface;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class UniKeyboard : MonoBehaviour, IKeyboard
public class UniKeyboard : MonoBehaviour
{
Dictionary<KeyCode, MotionKey> dictKeyCfgs = new Dictionary<KeyCode, MotionKey>();
KeyCode[] CheckList;
MotionKey[] mCurrKey = new MotionKey[0];
List<MotionKey> temp = new List<MotionKey>();
public KeyCodeCore mKeyCodeCore = new KeyCodeCore();
#region
public UILongClickButton btnP1;
public UILongClickButton btnCoin1;
@ -17,16 +11,16 @@ public class UniKeyboard : MonoBehaviour, IKeyboard
public UILongClickButton btnB;
public UILongClickButton btnC;
public UILongClickButton btnD;
public UILongClickButton btnE;
public UILongClickButton btnF;
//public UILongClickButton btnE;
//public UILongClickButton btnF;
public UILongClickButton btnAB;
public UILongClickButton btnCD;
public UILongClickButton btnABC;
FloatingJoystick mJoystick;
public Transform tfKeyPad;
public FloatingJoystick mJoystick;
#endregion
List<UILongClickButton> mUIBtns = new List<UILongClickButton>();
public List<UILongClickButton> mUIBtns = new List<UILongClickButton>();
void Awake()
{
@ -38,112 +32,46 @@ public class UniKeyboard : MonoBehaviour, IKeyboard
btnB = GameObject.Find("btnB").GetComponent<UILongClickButton>();
btnC = GameObject.Find("btnC").GetComponent<UILongClickButton>();
btnD = GameObject.Find("btnD").GetComponent<UILongClickButton>();
btnE = GameObject.Find("btnE").GetComponent<UILongClickButton>();
btnF = GameObject.Find("btnF").GetComponent<UILongClickButton>();
//btnE = GameObject.Find("btnE")?.GetComponent<UILongClickButton>();
//btnF = GameObject.Find("btnF")?.GetComponent<UILongClickButton>();
btnAB = GameObject.Find("btnAB").GetComponent<UILongClickButton>();
btnCD = GameObject.Find("btnCD").GetComponent<UILongClickButton>();
btnABC = GameObject.Find("btnABC").GetComponent<UILongClickButton>();
btnE.gameObject.SetActive(false);
btnF.gameObject.SetActive(false);
#if UNITY_STANDALONE_WIN || UNITY_EDITOR
tfKeyPad.gameObject.SetActive(false);
#endif
dictKeyCfgs.Add(KeyCode.P, MotionKey.EMU_PAUSED);
dictKeyCfgs.Add(KeyCode.Alpha1, MotionKey.P1_GAMESTART);
dictKeyCfgs.Add(KeyCode.Alpha5, MotionKey.P1_INSERT_COIN);
dictKeyCfgs.Add(KeyCode.W, MotionKey.P1_UP);
dictKeyCfgs.Add(KeyCode.S, MotionKey.P1_DOWN);
dictKeyCfgs.Add(KeyCode.A, MotionKey.P1_LEFT);
dictKeyCfgs.Add(KeyCode.D, MotionKey.P1_RIGHT);
dictKeyCfgs.Add(KeyCode.J, MotionKey.P1_BTN_1);
dictKeyCfgs.Add(KeyCode.K, MotionKey.P1_BTN_2);
dictKeyCfgs.Add(KeyCode.L, MotionKey.P1_BTN_3);
dictKeyCfgs.Add(KeyCode.U, MotionKey.P1_BTN_4);
dictKeyCfgs.Add(KeyCode.KeypadDivide, MotionKey.P2_GAMESTART);
dictKeyCfgs.Add(KeyCode.KeypadMultiply, MotionKey.P2_INSERT_COIN);
dictKeyCfgs.Add(KeyCode.UpArrow, MotionKey.P2_UP);
dictKeyCfgs.Add(KeyCode.DownArrow, MotionKey.P2_DOWN);
dictKeyCfgs.Add(KeyCode.LeftArrow, MotionKey.P2_LEFT);
dictKeyCfgs.Add(KeyCode.RightArrow, MotionKey.P2_RIGHT);
dictKeyCfgs.Add(KeyCode.Keypad1, MotionKey.P2_BTN_1);
dictKeyCfgs.Add(KeyCode.Keypad2, MotionKey.P2_BTN_2);
dictKeyCfgs.Add(KeyCode.Keypad3, MotionKey.P2_BTN_3);
dictKeyCfgs.Add(KeyCode.Keypad4, MotionKey.P2_BTN_4);
CheckList = dictKeyCfgs.Keys.ToArray();
btnP1.Key = new MotionKey[] { MotionKey.P1_GAMESTART };
btnCoin1.Key = new MotionKey[] { MotionKey.P1_INSERT_COIN };
btnA.Key = new MotionKey[] { MotionKey.P1_BTN_1 };
btnB.Key = new MotionKey[] { MotionKey.P1_BTN_2 };
btnC.Key = new MotionKey[] { MotionKey.P1_BTN_3 };
btnD.Key = new MotionKey[] { MotionKey.P1_BTN_4 };
btnE.Key = new MotionKey[] { MotionKey.P1_BTN_5 };
btnF.Key = new MotionKey[] { MotionKey.P1_BTN_6 };
btnAB.Key = new MotionKey[] { MotionKey.P1_BTN_1, MotionKey.P1_BTN_2 };
btnCD.Key = new MotionKey[] { MotionKey.P1_BTN_3, MotionKey.P1_BTN_4 };
btnABC.Key = new MotionKey[] { MotionKey.P1_BTN_1, MotionKey.P1_BTN_2, MotionKey.P1_BTN_3 };
mUIBtns.Add(btnP1);
mUIBtns.Add(btnCoin1);
mUIBtns.Add(btnA);
mUIBtns.Add(btnB);
mUIBtns.Add(btnC);
mUIBtns.Add(btnD);
mUIBtns.Add(btnE);
mUIBtns.Add(btnF);
mUIBtns.Add(btnAB);
mUIBtns.Add(btnCD);
mUIBtns.Add(btnABC);
//if (btnE != null)
//{
// mUIBtns.Add(btnE);
// btnE.gameObject.SetActive(false);
//}
//else
//{
// mUIBtns.Add(btnF);
// btnF.gameObject.SetActive(false);
//}
#if UNITY_STANDALONE_WIN || UNITY_EDITOR
tfKeyPad.gameObject.SetActive(false);
#endif
mKeyCodeCore.Init(this,false);
}
void OnEnable()
{
}
public MotionKey[] GetPressedKeys()
{
return mCurrKey;
}
void Update()
{
temp.Clear();
for (int i = 0; i < CheckList.Length; i++)
{
if (Input.GetKey(CheckList[i]))
temp.Add(dictKeyCfgs[CheckList[i]]);
}
for (int i = 0; i < mUIBtns.Count; i++)
{
if (mUIBtns[i].bHotKey)
{
for (int j = 0; j < mUIBtns[i].Key.Length; j++)
temp.Add(mUIBtns[i].Key[j]);
}
}
Vector2Int inputV2 = mJoystick.RawInputV2;
//Debug.Log($"{inputV2.x},{inputV2.y}");
if (inputV2.x > 0) temp.Add(MotionKey.P1_RIGHT); else if (inputV2.x < 0) temp.Add(MotionKey.P1_LEFT);
if (inputV2.y > 0) temp.Add(MotionKey.P1_UP); else if (inputV2.y < 0) temp.Add(MotionKey.P1_DOWN);
mCurrKey = temp.ToArray();
#if UNITY_EDITOR
string TempStr = "";
foreach (var item in mCurrKey)
{
TempStr += $"{item.ToString()}|";
}
if(!string.IsNullOrEmpty(TempStr))
Debug.Log(TempStr);
#endif
mKeyCodeCore.UpdateLogic();
}
}

View File

@ -1,4 +1,4 @@
using MAME.Core.run_interface;
using MAME.Core;
using UnityEngine;
public class UniLog : ILog

View File

@ -1,4 +1,4 @@
using MAME.Core.run_interface;
using MAME.Core;
using UnityEngine;
public class UniMouse : MonoBehaviour, IMouse

View File

@ -1,4 +1,4 @@
using MAME.Core.run_interface;
using MAME.Core;
using UnityEngine;
public class UniResources : IResources

View File

@ -1,4 +1,4 @@
using MAME.Core.run_interface;
using MAME.Core;
using System;
using UnityEngine;
@ -71,35 +71,6 @@ public class UniSoundPlayer : MonoBehaviour, ISoundPlayer
_buffer.Write(left / 32767.0f);
//_buffer.Write(right / 32767.0f);
}
return;
float[] floatdata = ConvertByteArrayToFloatArray(buffer, samples_a, 2);
for (int i = 0; i < samples_a; i++)
{
_buffer.Write(floatdata[i]);
}
}
float[] floatArray = new float[960];
public float[] ConvertByteArrayToFloatArray(byte[] buffer, int samples_a, int channels)
{
//int sampleCount = buffer.Length / (channels * 2); // 16位所以每个样本2字节
for (int i = 0; i < samples_a; i++)
{
// 读取左右声道
//short left = BitConverter.ToInt16(buffer, i * channels * 2);
//short right = BitConverter.ToInt16(buffer, i * channels * 2 + 2);
// 转换为-1.0到1.0的浮点数
//floatArray[i] = left / 32767.0f; // 32767是16位整数的最大值
//floatArray[i + 1] = right / 32767.0f;
short onedata = BitConverter.ToInt16(buffer, i * channels * 2);
floatArray[i] = onedata / 32767.0f;
}
return floatArray;
}
public void BufferWirte(int Off, byte[] Data)

View File

@ -1,7 +1,8 @@
using MAME.Core.run_interface;
using MAME.Core;
using System;
using UnityEngine;
using UnityEngine.UI;
using static TMPro.SpriteAssetUtilities.TexturePacker_JsonArray;
public class UniVideoPlayer : MonoBehaviour, IVideoPlayer
{
@ -22,10 +23,12 @@ public class UniVideoPlayer : MonoBehaviour, IVideoPlayer
private TimeSpan lastElapsed;
public double videoFPS { get; private set; }
public ulong mFrame { get; private set; }
bool bInit = false;
private void Awake()
{
mFrame = 0;
m_drawCanvas = GameObject.Find("GameRawImage").GetComponent<RawImage>();
m_drawCanvasrect = m_drawCanvas.GetComponent<RectTransform>();
}
@ -66,12 +69,20 @@ public class UniVideoPlayer : MonoBehaviour, IVideoPlayer
m_rawBufferWarper.Apply();
}
public void SubmitVideo(int[] data)
public void SubmitVideo(int[] data, long frame_number)
{
mFrame = (ulong)frame_number;
var current = UMAME.sw.Elapsed;
var delta = current - lastElapsed;
lastElapsed = current;
videoFPS = 1d / delta.TotalSeconds;
mFrameData = data;
//Debug.Log($"frame_number -> {frame_number}");
}
public byte[] GetScreenImg()
{
return (m_drawCanvas.texture as Texture2D).EncodeToJPG();
}
}