diff --git a/AxibugEmuOnline.Client/Assets/Script/IEmuCore.cs b/AxibugEmuOnline.Client/Assets/Script/IEmuCore.cs index c60b316..a054acf 100644 --- a/AxibugEmuOnline.Client/Assets/Script/IEmuCore.cs +++ b/AxibugEmuOnline.Client/Assets/Script/IEmuCore.cs @@ -6,12 +6,15 @@ namespace AxibugEmuOnline.Client { public interface IEmuCore { + GameObject gameObject { get; } + object GetState(); byte[] GetStateBytes(); void LoadState(object state); void LoadStateFromBytes(byte[] data); void Pause(); void Resume(); - void SetupScheme(); + void SetupScheme(); + void StartGame(RomFile romFile); } } diff --git a/AxibugEmuOnline.Client/Assets/Script/Manager/AppEmu.cs b/AxibugEmuOnline.Client/Assets/Script/Manager/AppEmu.cs index 6517770..4b59524 100644 --- a/AxibugEmuOnline.Client/Assets/Script/Manager/AppEmu.cs +++ b/AxibugEmuOnline.Client/Assets/Script/Manager/AppEmu.cs @@ -1,4 +1,5 @@ 锘縰sing AxibugEmuOnline.Client.ClientCore; +using MyNes.Core; using UnityEngine; namespace AxibugEmuOnline.Client.Manager @@ -6,6 +7,7 @@ namespace AxibugEmuOnline.Client.Manager public class AppEmu { private GameObject m_emuInstance; + private IEmuCore m_emuCore; public void BeginGame(RomFile romFile) { @@ -14,14 +16,17 @@ namespace AxibugEmuOnline.Client.Manager switch (romFile.Platform) { case EnumPlatform.NES: - var nesEmu = GameObject.Instantiate(Resources.Load("NES/NesEmulator")).GetComponent(); - m_emuInstance = nesEmu.gameObject; - - nesEmu.StartGame(romFile); - LaunchUI.Instance.HideMainMenu(); - InGameUI.Instance.Show(romFile, nesEmu); + m_emuCore = GameObject.Instantiate(Resources.Load("NES/NesEmulator")).GetComponent(); break; } + + m_emuInstance = m_emuCore.gameObject; + + m_emuCore.StartGame(romFile); + LaunchUI.Instance.HideMainMenu(); + InGameUI.Instance.Show(romFile, m_emuCore); + + m_emuCore.SetupScheme(); } public void StopGame() @@ -32,6 +37,8 @@ namespace AxibugEmuOnline.Client.Manager InGameUI.Instance.Hide(); LaunchUI.Instance.ShowMainMenu(); + + ControlScheme.Current = ControlSchemeSetts.Normal; } } } diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandDispatcher.cs b/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandDispatcher.cs index d953740..3beece3 100644 --- a/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandDispatcher.cs +++ b/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandDispatcher.cs @@ -74,8 +74,12 @@ namespace AxibugEmuOnline.Client } } + //键位映射表需要在按键响应的堆栈结束后处理,防止迭代器修改问题 if (m_waitMapperSetting != null) + { m_keyMapper = m_waitMapperSetting; + m_waitMapperSetting = null; + } } private Dictionary m_waitMapperSetting = null; diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI.cs b/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI.cs index 2e402b1..22f3f50 100644 --- a/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI.cs +++ b/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI.cs @@ -12,7 +12,7 @@ namespace AxibugEmuOnline.Client public override bool Enable => gameObject.activeInHierarchy; /// 指示该游戏实例是否处于联网模式 - public bool IsOnline => App.roomMgr.RoomState > AxibugProtobuf.RoomGameState.OnlyHost; + public bool IsOnline => App.user.IsLoggedIn ? App.roomMgr.RoomState > AxibugProtobuf.RoomGameState.OnlyHost : false; private RomFile m_rom; public IEmuCore Core { get; private set; } @@ -57,6 +57,7 @@ namespace AxibugEmuOnline.Client public void Show(RomFile currentRom, IEmuCore core) { + m_state = null;//清空游戏快照 CommandDispatcher.Instance.RegistController(this); m_rom = currentRom; @@ -69,6 +70,7 @@ namespace AxibugEmuOnline.Client } Eventer.Instance.RegisterEvent(EEvent.OnRoomWaitStepChange, OnServerStepUpdate); + OptionUI.Instance.OnHide += PopMenu_OnHide; gameObject.SetActiveEx(true); } @@ -82,14 +84,28 @@ namespace AxibugEmuOnline.Client { CommandDispatcher.Instance.UnRegistController(this); + OptionUI.Instance.OnHide -= PopMenu_OnHide; gameObject.SetActiveEx(false); } protected override void OnCmdOptionMenu() { OptionUI.Instance.Pop(menus); + + if (!IsOnline)//单人模式暂停模拟器 + { + Core.Pause(); + } } + //菜单关闭时候 + private void PopMenu_OnHide() + { + if (!IsOnline)//单人模式恢复模拟器的暂停 + Core.Resume(); + } + + public void QuitGame() { Eventer.Instance.UnregisterEvent(EEvent.OnRoomWaitStepChange, OnServerStepUpdate); diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/OptionUI/OptionUI.cs b/AxibugEmuOnline.Client/Assets/Script/UI/OptionUI/OptionUI.cs index e01c88a..f4bc4dd 100644 --- a/AxibugEmuOnline.Client/Assets/Script/UI/OptionUI/OptionUI.cs +++ b/AxibugEmuOnline.Client/Assets/Script/UI/OptionUI/OptionUI.cs @@ -24,6 +24,8 @@ namespace AxibugEmuOnline.Client private bool m_bPoped = false; private List m_runtimeMenuItems = new List(); + public event Action OnHide; + private int m_selectIndex = -1; public int SelectIndex { @@ -178,6 +180,8 @@ namespace AxibugEmuOnline.Client m_bPoped = false; ControlScheme.Current = m_lastCS; + + OnHide?.Invoke(); } }