diff --git a/AxibugEmuOnline.Client/Assets/Script/IEmuCore.cs b/AxibugEmuOnline.Client/Assets/Script/IEmuCore.cs
index a054acf..34c04d6 100644
--- a/AxibugEmuOnline.Client/Assets/Script/IEmuCore.cs
+++ b/AxibugEmuOnline.Client/Assets/Script/IEmuCore.cs
@@ -1,5 +1,3 @@
-using System.Collections;
-using System.Collections.Generic;
using UnityEngine;
namespace AxibugEmuOnline.Client
@@ -17,4 +15,13 @@ namespace AxibugEmuOnline.Client
void SetupScheme();
void StartGame(RomFile romFile);
}
+
+ public static class IEnumCoreTool
+ {
+ public static bool IsNull(this IEmuCore core)
+ {
+ if (core == null) return true;
+ return core.Equals(null);
+ }
+ }
}
diff --git a/AxibugEmuOnline.Client/Assets/Script/Manager/AppEmu.cs b/AxibugEmuOnline.Client/Assets/Script/Manager/AppEmu.cs
index 4b59524..697bf68 100644
--- a/AxibugEmuOnline.Client/Assets/Script/Manager/AppEmu.cs
+++ b/AxibugEmuOnline.Client/Assets/Script/Manager/AppEmu.cs
@@ -1,17 +1,47 @@
using AxibugEmuOnline.Client.ClientCore;
+using AxibugEmuOnline.Client.Event;
using MyNes.Core;
+using System;
using UnityEngine;
namespace AxibugEmuOnline.Client.Manager
{
public class AppEmu
{
- private GameObject m_emuInstance;
+ ///
+ /// unity的c#实现有bug,以接口类型保存的monobehaviour引用,!=和==运算符没有调用到monobehaviour重写过的运算符
+ /// 但是Equals方法可以,所以,这个接口判断为空请使用Equals
+ ///
private IEmuCore m_emuCore;
+ public AppEmu()
+ {
+ Eventer.Instance.RegisterEvent(EEvent.OnMineJoinRoom, OnSelfJoinRoom);
+ }
+
+ private void OnSelfJoinRoom()
+ {
+ //如果当前正在游戏中,就先结束游戏
+ if (!m_emuCore.IsNull()) StopGame();
+
+ var roomInfo = App.roomMgr.mineRoomMiniInfo;
+ roomInfo.FetchRomFileInRoomInfo(EnumPlatform.NES, (room, romFile) =>
+ {
+ if (!romFile.RomReady) //这个rom并没有下载,所以取消进入房间
+ {
+ App.roomMgr.SendLeavnRoom();
+ }
+ else
+ {
+ BeginGame(romFile);
+ }
+ });
+ }
+
+
public void BeginGame(RomFile romFile)
{
- if (m_emuInstance != null) return;
+ if (!m_emuCore.Equals(null)) return;
switch (romFile.Platform)
{
@@ -20,8 +50,6 @@ namespace AxibugEmuOnline.Client.Manager
break;
}
- m_emuInstance = m_emuCore.gameObject;
-
m_emuCore.StartGame(romFile);
LaunchUI.Instance.HideMainMenu();
InGameUI.Instance.Show(romFile, m_emuCore);
@@ -31,9 +59,9 @@ namespace AxibugEmuOnline.Client.Manager
public void StopGame()
{
- if (m_emuInstance == null) return;
- GameObject.Destroy(m_emuInstance);
- m_emuInstance = null;
+ if (m_emuCore.IsNull()) return;
+ GameObject.Destroy(m_emuCore.gameObject);
+ m_emuCore = null;
InGameUI.Instance.Hide();
LaunchUI.Instance.ShowMainMenu();
diff --git a/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/RomFile.cs b/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/RomFile.cs
index a4eb71a..0508534 100644
--- a/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/RomFile.cs
+++ b/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/RomFile.cs
@@ -48,7 +48,7 @@ namespace AxibugEmuOnline.Client
public int Page { get; private set; }
public string Hash => webData != null ? webData.hash : string.Empty;
- public event Action OnDownloadOver;
+ public event Action OnDownloadOver;
public event Action OnInfoFilled;
public RomFile(EnumPlatform platform, int index, int insidePage)
@@ -73,7 +73,7 @@ namespace AxibugEmuOnline.Client
File.WriteAllBytes(LocalFilePath, bytes);
hasLocalFile = true;
}
- OnDownloadOver?.Invoke();
+ OnDownloadOver?.Invoke(this);
}));
}
@@ -115,13 +115,16 @@ namespace AxibugEmuOnline.Client
downloadRequest = UnityWebRequest.Get($"{App.httpAPI.WebHost}/{webData.url}");
yield return downloadRequest.SendWebRequest();
- if (downloadRequest.result != UnityWebRequest.Result.Success)
+ var request = downloadRequest;
+ downloadRequest = null;
+
+ if (request.result != UnityWebRequest.Result.Success)
{
callback(null);
}
else
{
- callback(downloadRequest.downloadHandler.data);
+ callback(request.downloadHandler.data);
}
}
diff --git a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.cs b/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.cs
index 4061b1c..69d64fe 100644
--- a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.cs
+++ b/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.cs
@@ -69,7 +69,6 @@ namespace AxibugEmuOnline.Client
}
}
-
public void Pause()
{
m_bPause = true;
diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/StepPerformer.cs b/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/StepPerformer.cs
index 9564601..1b3f342 100644
--- a/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/StepPerformer.cs
+++ b/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/StepPerformer.cs
@@ -18,7 +18,6 @@ namespace AxibugEmuOnline.Client
{
m_step = step;
-
switch (m_step)
{
//等待主机上报快照
diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/RoomItem.cs b/AxibugEmuOnline.Client/Assets/Script/UI/RoomItem.cs
index aed1d9d..6db698c 100644
--- a/AxibugEmuOnline.Client/Assets/Script/UI/RoomItem.cs
+++ b/AxibugEmuOnline.Client/Assets/Script/UI/RoomItem.cs
@@ -2,6 +2,7 @@ using AxibugEmuOnline.Client.ClientCore;
using AxibugEmuOnline.Client.Event;
using AxibugEmuOnline.Client.UI;
using AxibugProtobuf;
+using System;
using UnityEngine;
using UnityEngine.UI;
@@ -23,6 +24,20 @@ namespace AxibugEmuOnline.Client
public int Index { get; set; }
public int roomID { get; private set; }
+ protected override void Awake()
+ {
+ base.Awake();
+
+ Eventer.Instance.RegisterEvent(EEvent.OnRoomListSingleUpdate, OnRoomSignelUpdate);
+ }
+
+ private void OnRoomSignelUpdate(int roomID)
+ {
+ if (this.roomID != roomID) return;
+
+ if (App.roomMgr.GetRoomListMiniInfo(roomID, out var roomInfo))
+ UpdateUI(roomInfo);
+ }
public void SetData(object data)
{
@@ -53,12 +68,12 @@ namespace AxibugEmuOnline.Client
SetBaseInfo(string.Empty, $"{hostNick}ķ - {cur}/{max}");
SetIcon(null);
- roomInfo.FetchRomFileInRoomInfo(EnumPlatform.NES, (romFile) =>
+ roomInfo.FetchRomFileInRoomInfo(EnumPlatform.NES, (room, romFile) =>
{
- m_romFile = romFile;
+ if (room.RoomID != roomID) return;
- if (romFile.ID == roomInfo.GameRomID)
- Txt.text = romFile.Alias;
+ m_romFile = romFile;
+ Txt.text = romFile.Alias;
UpdateRomInfoView();
App.CacheMgr.GetSpriteCache(romFile.ImageURL, OnGetRomImage);
diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/RoomListMenuItem.cs b/AxibugEmuOnline.Client/Assets/Script/UI/RoomListMenuItem.cs
index b18f9da..48a2fb3 100644
--- a/AxibugEmuOnline.Client/Assets/Script/UI/RoomListMenuItem.cs
+++ b/AxibugEmuOnline.Client/Assets/Script/UI/RoomListMenuItem.cs
@@ -12,7 +12,7 @@ namespace AxibugEmuOnline.Client
{
Eventer.Instance.RegisterEvent(EEvent.OnRoomListAllUpdate, OnRoomListUpdateAll);
Eventer.Instance.RegisterEvent(EEvent.OnRoomListSingleClose, OnRoomClosed);
- Eventer.Instance.RegisterEvent(EEvent.OnRoomListSingleUpdate, OnRoomSingleUpdate);
+ Eventer.Instance.RegisterEvent(EEvent.OnRoomListSingleAdd, OnRoomSingleAdd);
base.Awake();
}
@@ -20,7 +20,7 @@ namespace AxibugEmuOnline.Client
protected override void OnDestroy()
{
Eventer.Instance.UnregisterEvent(EEvent.OnRoomListAllUpdate, OnRoomListUpdateAll);
- Eventer.Instance.UnregisterEvent(EEvent.OnRoomListSingleUpdate, OnRoomSingleUpdate);
+ Eventer.Instance.UnregisterEvent(EEvent.OnRoomListSingleUpdate, OnRoomSingleAdd);
Eventer.Instance.UnregisterEvent(EEvent.OnRoomListSingleClose, OnRoomClosed);
}
@@ -38,7 +38,7 @@ namespace AxibugEmuOnline.Client
return res;
}
- private void OnRoomSingleUpdate(int obj)
+ private void OnRoomSingleAdd(int obj)
{
if (m_entering)
{
diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/VirtualSubMenuItem.cs b/AxibugEmuOnline.Client/Assets/Script/UI/VirtualSubMenuItem.cs
index 9721a82..859d9de 100644
--- a/AxibugEmuOnline.Client/Assets/Script/UI/VirtualSubMenuItem.cs
+++ b/AxibugEmuOnline.Client/Assets/Script/UI/VirtualSubMenuItem.cs
@@ -20,7 +20,7 @@ namespace AxibugEmuOnline.Client
base.Awake();
RomGroupRoot.gameObject.SetActive(false);
- RomGroupRoot.alpha = 0;
+ RomGroupRoot.alpha = 0;
}
public override void SetSelectState(bool selected)
@@ -58,7 +58,7 @@ namespace AxibugEmuOnline.Client
thirdMenuGroup.itemGroup.Clear();
RefreshUI();
-
+
if (SubMenuItemGroup != null) SubMenuItemGroup.SetSelect(true);
return true;
diff --git a/AxibugEmuOnline.Client/Assets/Script/Utility.cs b/AxibugEmuOnline.Client/Assets/Script/Utility.cs
index 58bc19b..973471a 100644
--- a/AxibugEmuOnline.Client/Assets/Script/Utility.cs
+++ b/AxibugEmuOnline.Client/Assets/Script/Utility.cs
@@ -38,11 +38,11 @@ namespace AxibugEmuOnline.Client
}
private static Dictionary s_RomFileCahcesInRoomInfo = new Dictionary();
- public static void FetchRomFileInRoomInfo(this Protobuf_Room_MiniInfo roomInfo, EnumPlatform platform, Action callback)
+ public static void FetchRomFileInRoomInfo(this Protobuf_Room_MiniInfo roomInfo, EnumPlatform platform, Action callback)
{
if (s_RomFileCahcesInRoomInfo.TryGetValue(roomInfo.GameRomID, out RomFile romFile))
{
- callback.Invoke(romFile);
+ callback.Invoke(roomInfo,romFile);
return;
}
switch (platform)
@@ -52,9 +52,9 @@ namespace AxibugEmuOnline.Client
{
RomFile romFile = new RomFile(EnumPlatform.NES, 0, 0);
romFile.SetWebData(romWebData);
- callback.Invoke(romFile);
-
s_RomFileCahcesInRoomInfo[roomInfo.GameRomID] = romFile;
+
+ callback.Invoke(roomInfo,romFile);
}));
break;
}