Compare commits

..

No commits in common. "5863a6798fa4f293084acd7fb3f7636a6460fff5" and "43a7cca0919b62e0559da79f023fe4c0ab476ff7" have entirely different histories.

9 changed files with 36 additions and 90 deletions

View File

@ -1,3 +1,5 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
namespace AxibugEmuOnline.Client namespace AxibugEmuOnline.Client
@ -15,13 +17,4 @@ namespace AxibugEmuOnline.Client
void SetupScheme(); void SetupScheme();
void StartGame(RomFile romFile); void StartGame(RomFile romFile);
} }
public static class IEnumCoreTool
{
public static bool IsNull(this IEmuCore core)
{
if (core == null) return true;
return core.Equals(null);
}
}
} }

View File

@ -1,47 +1,17 @@
using AxibugEmuOnline.Client.ClientCore; using AxibugEmuOnline.Client.ClientCore;
using AxibugEmuOnline.Client.Event;
using MyNes.Core; using MyNes.Core;
using System;
using UnityEngine; using UnityEngine;
namespace AxibugEmuOnline.Client.Manager namespace AxibugEmuOnline.Client.Manager
{ {
public class AppEmu public class AppEmu
{ {
/// <summary> private GameObject m_emuInstance;
/// unity的c#实现有bug,以接口类型保存的monobehaviour引用,!=和==运算符没有调用到monobehaviour重写过的运算符
/// 但是Equals方法可以,所以,这个接口判断为空请使用Equals
/// </summary>
private IEmuCore m_emuCore; 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) public void BeginGame(RomFile romFile)
{ {
if (!m_emuCore.Equals(null)) return; if (m_emuInstance != null) return;
switch (romFile.Platform) switch (romFile.Platform)
{ {
@ -50,6 +20,8 @@ namespace AxibugEmuOnline.Client.Manager
break; break;
} }
m_emuInstance = m_emuCore.gameObject;
m_emuCore.StartGame(romFile); m_emuCore.StartGame(romFile);
LaunchUI.Instance.HideMainMenu(); LaunchUI.Instance.HideMainMenu();
InGameUI.Instance.Show(romFile, m_emuCore); InGameUI.Instance.Show(romFile, m_emuCore);
@ -59,9 +31,9 @@ namespace AxibugEmuOnline.Client.Manager
public void StopGame() public void StopGame()
{ {
if (m_emuCore.IsNull()) return; if (m_emuInstance == null) return;
GameObject.Destroy(m_emuCore.gameObject); GameObject.Destroy(m_emuInstance);
m_emuCore = null; m_emuInstance = null;
InGameUI.Instance.Hide(); InGameUI.Instance.Hide();
LaunchUI.Instance.ShowMainMenu(); LaunchUI.Instance.ShowMainMenu();

View File

@ -48,7 +48,7 @@ namespace AxibugEmuOnline.Client
public int Page { get; private set; } public int Page { get; private set; }
public string Hash => webData != null ? webData.hash : string.Empty; public string Hash => webData != null ? webData.hash : string.Empty;
public event Action<RomFile> OnDownloadOver; public event Action OnDownloadOver;
public event Action OnInfoFilled; public event Action OnInfoFilled;
public RomFile(EnumPlatform platform, int index, int insidePage) public RomFile(EnumPlatform platform, int index, int insidePage)
@ -73,7 +73,7 @@ namespace AxibugEmuOnline.Client
File.WriteAllBytes(LocalFilePath, bytes); File.WriteAllBytes(LocalFilePath, bytes);
hasLocalFile = true; hasLocalFile = true;
} }
OnDownloadOver?.Invoke(this); OnDownloadOver?.Invoke();
})); }));
} }
@ -115,16 +115,13 @@ namespace AxibugEmuOnline.Client
downloadRequest = UnityWebRequest.Get($"{App.httpAPI.WebHost}/{webData.url}"); downloadRequest = UnityWebRequest.Get($"{App.httpAPI.WebHost}/{webData.url}");
yield return downloadRequest.SendWebRequest(); yield return downloadRequest.SendWebRequest();
var request = downloadRequest; if (downloadRequest.result != UnityWebRequest.Result.Success)
downloadRequest = null;
if (request.result != UnityWebRequest.Result.Success)
{ {
callback(null); callback(null);
} }
else else
{ {
callback(request.downloadHandler.data); callback(downloadRequest.downloadHandler.data);
} }
} }

View File

@ -69,6 +69,7 @@ namespace AxibugEmuOnline.Client
} }
} }
public void Pause() public void Pause()
{ {
m_bPause = true; m_bPause = true;

View File

@ -18,6 +18,7 @@ namespace AxibugEmuOnline.Client
{ {
m_step = step; m_step = step;
switch (m_step) switch (m_step)
{ {
//等待主机上报快照 //等待主机上报快照

View File

@ -2,7 +2,6 @@ using AxibugEmuOnline.Client.ClientCore;
using AxibugEmuOnline.Client.Event; using AxibugEmuOnline.Client.Event;
using AxibugEmuOnline.Client.UI; using AxibugEmuOnline.Client.UI;
using AxibugProtobuf; using AxibugProtobuf;
using System;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
@ -28,15 +27,22 @@ namespace AxibugEmuOnline.Client
{ {
base.Awake(); base.Awake();
Eventer.Instance.RegisterEvent<int>(EEvent.OnRoomListSingleUpdate, OnRoomSignelUpdate); Eventer.Instance.RegisterEvent<int>(EEvent.OnRoomListSingleUpdate, OnRoomSingleUpdate);
} }
private void OnRoomSignelUpdate(int roomID) protected override void OnDestroy()
{ {
if (this.roomID != roomID) return; Eventer.Instance.UnregisterEvent<int>(EEvent.OnRoomListSingleUpdate, OnRoomSingleUpdate);
}
if (App.roomMgr.GetRoomListMiniInfo(roomID, out var roomInfo)) private void OnRoomSingleUpdate(int roomId)
{
if (roomId != roomID) return;
if (App.roomMgr.GetRoomListMiniInfo(roomId, out var roomInfo))
{
UpdateUI(roomInfo); UpdateUI(roomInfo);
}
} }
public void SetData(object data) public void SetData(object data)
@ -47,20 +53,6 @@ namespace AxibugEmuOnline.Client
UpdateUI(roomInfo); UpdateUI(roomInfo);
} }
public override bool OnEnterItem()
{
if (!m_romFile.RomReady)
{
m_romFile.BeginDownload();
return false;
}
else
{
App.roomMgr.SendJoinRoom(roomID, 1);
return true;
}
}
private void UpdateUI(Protobuf_Room_MiniInfo roomInfo) private void UpdateUI(Protobuf_Room_MiniInfo roomInfo)
{ {
var hostNick = roomInfo.GetHostNickName(); var hostNick = roomInfo.GetHostNickName();
@ -68,12 +60,12 @@ namespace AxibugEmuOnline.Client
SetBaseInfo(string.Empty, $"<b>{hostNick}</b>ľÄˇżźä - {cur}/{max}"); SetBaseInfo(string.Empty, $"<b>{hostNick}</b>ľÄˇżźä - {cur}/{max}");
SetIcon(null); SetIcon(null);
roomInfo.FetchRomFileInRoomInfo(EnumPlatform.NES, (room, romFile) => roomInfo.FetchRomFileInRoomInfo(EnumPlatform.NES, (romFile) =>
{ {
if (room.RoomID != roomID) return;
m_romFile = romFile; m_romFile = romFile;
Txt.text = romFile.Alias;
if (romFile.ID == roomInfo.GameRomID)
Txt.text = romFile.Alias;
UpdateRomInfoView(); UpdateRomInfoView();
App.CacheMgr.GetSpriteCache(romFile.ImageURL, OnGetRomImage); App.CacheMgr.GetSpriteCache(romFile.ImageURL, OnGetRomImage);

View File

@ -12,7 +12,6 @@ namespace AxibugEmuOnline.Client
{ {
Eventer.Instance.RegisterEvent<int>(EEvent.OnRoomListAllUpdate, OnRoomListUpdateAll); Eventer.Instance.RegisterEvent<int>(EEvent.OnRoomListAllUpdate, OnRoomListUpdateAll);
Eventer.Instance.RegisterEvent<int>(EEvent.OnRoomListSingleClose, OnRoomClosed); Eventer.Instance.RegisterEvent<int>(EEvent.OnRoomListSingleClose, OnRoomClosed);
Eventer.Instance.RegisterEvent<int>(EEvent.OnRoomListSingleAdd, OnRoomSingleAdd);
base.Awake(); base.Awake();
} }
@ -20,7 +19,6 @@ namespace AxibugEmuOnline.Client
protected override void OnDestroy() protected override void OnDestroy()
{ {
Eventer.Instance.UnregisterEvent<int>(EEvent.OnRoomListAllUpdate, OnRoomListUpdateAll); Eventer.Instance.UnregisterEvent<int>(EEvent.OnRoomListAllUpdate, OnRoomListUpdateAll);
Eventer.Instance.UnregisterEvent<int>(EEvent.OnRoomListSingleUpdate, OnRoomSingleAdd);
Eventer.Instance.UnregisterEvent<int>(EEvent.OnRoomListSingleClose, OnRoomClosed); Eventer.Instance.UnregisterEvent<int>(EEvent.OnRoomListSingleClose, OnRoomClosed);
} }
@ -38,14 +36,6 @@ namespace AxibugEmuOnline.Client
return res; return res;
} }
private void OnRoomSingleAdd(int obj)
{
if (m_entering)
{
RefreshUI();
}
}
private void OnRoomListUpdateAll(int obj) private void OnRoomListUpdateAll(int obj)
{ {
if (m_entering) if (m_entering)

View File

@ -38,11 +38,11 @@ namespace AxibugEmuOnline.Client
} }
private static Dictionary<int, RomFile> s_RomFileCahcesInRoomInfo = new Dictionary<int, RomFile>(); private static Dictionary<int, RomFile> s_RomFileCahcesInRoomInfo = new Dictionary<int, RomFile>();
public static void FetchRomFileInRoomInfo(this Protobuf_Room_MiniInfo roomInfo, EnumPlatform platform, Action<Protobuf_Room_MiniInfo, RomFile> callback) public static void FetchRomFileInRoomInfo(this Protobuf_Room_MiniInfo roomInfo, EnumPlatform platform, Action<RomFile> callback)
{ {
if (s_RomFileCahcesInRoomInfo.TryGetValue(roomInfo.GameRomID, out RomFile romFile)) if (s_RomFileCahcesInRoomInfo.TryGetValue(roomInfo.GameRomID, out RomFile romFile))
{ {
callback.Invoke(roomInfo,romFile); callback.Invoke(romFile);
return; return;
} }
switch (platform) switch (platform)
@ -52,9 +52,9 @@ namespace AxibugEmuOnline.Client
{ {
RomFile romFile = new RomFile(EnumPlatform.NES, 0, 0); RomFile romFile = new RomFile(EnumPlatform.NES, 0, 0);
romFile.SetWebData(romWebData); romFile.SetWebData(romWebData);
s_RomFileCahcesInRoomInfo[roomInfo.GameRomID] = romFile; callback.Invoke(romFile);
callback.Invoke(roomInfo,romFile); s_RomFileCahcesInRoomInfo[roomInfo.GameRomID] = romFile;
})); }));
break; break;
} }