MAME实现多玩家动态插入

This commit is contained in:
sin365 2025-01-25 02:28:01 +08:00
parent da5a155c88
commit 8858c43468

View File

@ -7,6 +7,9 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
using static AxibugEmuOnline.Client.NesControllerMapper;
using static UnityEditor.VersionControl.Asset;
using VirtualNes.Core;
public class UniKeyboard : MonoBehaviour, IKeyboard public class UniKeyboard : MonoBehaviour, IKeyboard
{ {
@ -137,9 +140,27 @@ public class UniKeyboard : MonoBehaviour, IKeyboard
//дÈëreplay //дÈëreplay
UMAME.instance.mReplayWriter.NextFramebyFrameIdx((int)UMAME.instance.mUniVideoPlayer.mFrame, CurrLocalInpuAllData); UMAME.instance.mReplayWriter.NextFramebyFrameIdx((int)UMAME.instance.mUniVideoPlayer.mFrame, CurrLocalInpuAllData);
CheckPlayerSlotChanged();
return CurrLocalInpuAllData; return CurrLocalInpuAllData;
} }
void CheckPlayerSlotChanged()
{
if (!mUniKeyboard.ControllerMapper.Controller0.ConnectSlot.HasValue && mUniKeyboard.ControllerMapper.Controller0.AnyButtonDown())
Eventer.Instance.PostEvent(EEvent.OnLocalJoyDesireInvert, 0);
if (!mUniKeyboard.ControllerMapper.Controller1.ConnectSlot.HasValue && mUniKeyboard.ControllerMapper.Controller1.AnyButtonDown())
Eventer.Instance.PostEvent(EEvent.OnLocalJoyDesireInvert, 1);
if (!mUniKeyboard.ControllerMapper.Controller2.ConnectSlot.HasValue && mUniKeyboard.ControllerMapper.Controller2.AnyButtonDown())
Eventer.Instance.PostEvent(EEvent.OnLocalJoyDesireInvert, 2);
if (!mUniKeyboard.ControllerMapper.Controller3.ConnectSlot.HasValue && mUniKeyboard.ControllerMapper.Controller3.AnyButtonDown())
Eventer.Instance.PostEvent(EEvent.OnLocalJoyDesireInvert, 3);
}
} }
public class ReplayMode public class ReplayMode
{ {
@ -174,10 +195,10 @@ public class UniKeyboard : MonoBehaviour, IKeyboard
public class MameControllerMapper : IControllerSetuper public class MameControllerMapper : IControllerSetuper
{ {
public MameSingleConoller Controller0 { get; } = new MameSingleConoller(0); public MameSingleConoller Controller0 = new MameSingleConoller(0);
public MameSingleConoller Controller1 { get; } = new MameSingleConoller(1); public MameSingleConoller Controller1 = new MameSingleConoller(1);
public MameSingleConoller Controller2 { get; } = new MameSingleConoller(2); public MameSingleConoller Controller2 = new MameSingleConoller(2);
public MameSingleConoller Controller3 { get; } = new MameSingleConoller(3); public MameSingleConoller Controller3 = new MameSingleConoller(3);
ulong mCurrAllInput; ulong mCurrAllInput;
@ -191,7 +212,6 @@ public class MameControllerMapper : IControllerSetuper
Controller2.ConnectSlot = con2ToSlot; Controller2.ConnectSlot = con2ToSlot;
Controller3.ConnectSlot = con3ToSlot; Controller3.ConnectSlot = con3ToSlot;
} }
public int? GetSlotConnectingControllerIndex(int slotIndex) public int? GetSlotConnectingControllerIndex(int slotIndex)
{ {
if (Controller0.ConnectSlot.HasValue && Controller0.ConnectSlot.Value == slotIndex) return 0; if (Controller0.ConnectSlot.HasValue && Controller0.ConnectSlot.Value == slotIndex) return 0;
@ -200,7 +220,6 @@ public class MameControllerMapper : IControllerSetuper
else if (Controller3.ConnectSlot.HasValue && Controller3.ConnectSlot.Value == slotIndex) return 3; else if (Controller3.ConnectSlot.HasValue && Controller3.ConnectSlot.Value == slotIndex) return 3;
else return null; else return null;
} }
public IController GetSlotConnectingController(int slotIndex) public IController GetSlotConnectingController(int slotIndex)
{ {
if (Controller0.ConnectSlot.HasValue && Controller0.ConnectSlot.Value == slotIndex) return Controller0; if (Controller0.ConnectSlot.HasValue && Controller0.ConnectSlot.Value == slotIndex) return Controller0;
@ -226,8 +245,6 @@ public class MameControllerMapper : IControllerSetuper
if (s_temp.Count > 0) return s_temp.First(); if (s_temp.Count > 0) return s_temp.First();
else return null; else return null;
} }
public void LetControllerConnect(int conIndex, uint slotIndex) public void LetControllerConnect(int conIndex, uint slotIndex)
{ {
MameSingleConoller targetController; MameSingleConoller targetController;
@ -262,7 +279,7 @@ public class MameSingleConoller : IController
tg_UP, tg_DOWN, tg_LEFT, tg_RIGHT, tg_UP, tg_DOWN, tg_LEFT, tg_RIGHT,
tg_BTN_A, tg_BTN_B, tg_BTN_C, tg_BTN_D, tg_BTN_E, tg_BTN_F; tg_BTN_A, tg_BTN_B, tg_BTN_C, tg_BTN_D, tg_BTN_E, tg_BTN_F;
ulong mTempSingleAllInput; public ulong CurrLocalSingleAllInput { get; private set; }
int mControllerIndex; int mControllerIndex;
uint? mConnectSlot; uint? mConnectSlot;
@ -295,38 +312,38 @@ public class MameSingleConoller : IController
public bool AnyButtonDown() public bool AnyButtonDown()
{ {
//if (Input.GetKeyDown(INSERT_COIN)) return true; if (Input.GetKeyDown(INSERT_COIN)) return true;
//if (Input.GetKeyDown(GAMESTART)) return true; if (Input.GetKeyDown(GAMESTART)) return true;
//if (Input.GetKeyDown(UP)) return true; if (Input.GetKeyDown(UP)) return true;
//if (Input.GetKeyDown(DOWN)) return true; if (Input.GetKeyDown(DOWN)) return true;
//if (Input.GetKeyDown(LEFT)) return true; if (Input.GetKeyDown(LEFT)) return true;
//if (Input.GetKeyDown(RIGHT)) return true; if (Input.GetKeyDown(RIGHT)) return true;
//if (Input.GetKeyDown(BTN_A)) return true; if (Input.GetKeyDown(BTN_A)) return true;
//if (Input.GetKeyDown(BTN_B)) return true; if (Input.GetKeyDown(BTN_B)) return true;
//if (Input.GetKeyDown(BTN_C)) return true; if (Input.GetKeyDown(BTN_C)) return true;
//if (Input.GetKeyDown(BTN_D)) return true; if (Input.GetKeyDown(BTN_D)) return true;
//if (Input.GetKeyDown(BTN_E)) return true; if (Input.GetKeyDown(BTN_E)) return true;
//if (Input.GetKeyDown(BTN_F)) return true; if (Input.GetKeyDown(BTN_F)) return true;
return mTempSingleAllInput > 0; return false;
} }
public ulong GetSingleAllInput() public ulong GetSingleAllInput()
{ {
if (!ConnectSlot.HasValue) if (!ConnectSlot.HasValue)
return 0; return 0;
mTempSingleAllInput = 0; CurrLocalSingleAllInput = 0;
if (Input.GetKey(INSERT_COIN)) mTempSingleAllInput |= (ulong)tg_INSERT_COIN; if (Input.GetKey(INSERT_COIN)) CurrLocalSingleAllInput |= (ulong)tg_INSERT_COIN;
if (Input.GetKey(GAMESTART)) mTempSingleAllInput |= (ulong)tg_GAMESTART; if (Input.GetKey(GAMESTART)) CurrLocalSingleAllInput |= (ulong)tg_GAMESTART;
if (Input.GetKey(UP)) mTempSingleAllInput |= (ulong)tg_UP; if (Input.GetKey(UP)) CurrLocalSingleAllInput |= (ulong)tg_UP;
if (Input.GetKey(DOWN)) mTempSingleAllInput |= (ulong)tg_DOWN; if (Input.GetKey(DOWN)) CurrLocalSingleAllInput |= (ulong)tg_DOWN;
if (Input.GetKey(LEFT)) mTempSingleAllInput |= (ulong)tg_LEFT; if (Input.GetKey(LEFT)) CurrLocalSingleAllInput |= (ulong)tg_LEFT;
if (Input.GetKey(RIGHT)) mTempSingleAllInput |= (ulong)tg_RIGHT; if (Input.GetKey(RIGHT)) CurrLocalSingleAllInput |= (ulong)tg_RIGHT;
if (Input.GetKey(BTN_A)) mTempSingleAllInput |= (ulong)tg_BTN_A; if (Input.GetKey(BTN_A)) CurrLocalSingleAllInput |= (ulong)tg_BTN_A;
if (Input.GetKey(BTN_B)) mTempSingleAllInput |= (ulong)tg_BTN_B; if (Input.GetKey(BTN_B)) CurrLocalSingleAllInput |= (ulong)tg_BTN_B;
if (Input.GetKey(BTN_C)) mTempSingleAllInput |= (ulong)tg_BTN_C; if (Input.GetKey(BTN_C)) CurrLocalSingleAllInput |= (ulong)tg_BTN_C;
if (Input.GetKey(BTN_D)) mTempSingleAllInput |= (ulong)tg_BTN_D; if (Input.GetKey(BTN_D)) CurrLocalSingleAllInput |= (ulong)tg_BTN_D;
if (Input.GetKey(BTN_E)) mTempSingleAllInput |= (ulong)tg_BTN_E; if (Input.GetKey(BTN_E)) CurrLocalSingleAllInput |= (ulong)tg_BTN_E;
if (Input.GetKey(BTN_F)) mTempSingleAllInput |= (ulong)tg_BTN_F; if (Input.GetKey(BTN_F)) CurrLocalSingleAllInput |= (ulong)tg_BTN_F;
return mTempSingleAllInput; return CurrLocalSingleAllInput;
} }
} }
@ -371,7 +388,6 @@ public static class MameSingleControllSetter
break; break;
} }
} }
public static void ResetTargetMotionKey(this MameSingleConoller singlecontrol) public static void ResetTargetMotionKey(this MameSingleConoller singlecontrol)
{ {
if (!singlecontrol.ConnectSlot.HasValue) if (!singlecontrol.ConnectSlot.HasValue)