From 88313eee6be649d146b971c289f663e4b82265be Mon Sep 17 00:00:00 2001 From: "ALIENJACK\\alien" Date: Thu, 7 Nov 2024 17:58:20 +0800 Subject: [PATCH] =?UTF-8?q?IEmuCore=E6=8E=A5=E5=8F=A3=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=8E=B7=E5=8F=96gameObject=E7=9A=84=E6=96=B9=E6=B3=95,?= =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=B8=B8=E6=88=8F=E4=B8=AD=E5=92=8CUI?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E7=9A=84=E6=93=8D=E4=BD=9C=E9=9B=86=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Assets/Script/IEmuCore.cs | 5 ++++- .../Assets/Script/Manager/AppEmu.cs | 19 +++++++++++++------ .../UI/CommandDispatcher/CommandDispatcher.cs | 4 ++++ .../Assets/Script/UI/InGameUI/InGameUI.cs | 18 +++++++++++++++++- .../Assets/Script/UI/OptionUI/OptionUI.cs | 4 ++++ 5 files changed, 42 insertions(+), 8 deletions(-) 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(); } }