Compare commits

...

5 Commits

Author SHA1 Message Date
5863a6798f Merge pull request 'master' (#41) from Alienjack/AxibugEmuOnline:master into master
Reviewed-on: #41
2024-11-08 11:34:30 +08:00
ALIENJACK\alien
814cc5ed5e 进入房间相关代码流程实现 2024-11-08 11:31:12 +08:00
ALIENJACK\alien
46a62ca9f7 Merge branch 'master' of http://git.axibug.com/sin365/AxibugEmuOnline 2024-11-08 10:03:17 +08:00
ALIENJACK\alien
323f7a44df 迭代 2024-11-07 20:33:44 +08:00
ALIENJACK\alien
7b85fd8ce8 迭代 2024-11-07 20:20:53 +08:00
9 changed files with 90 additions and 36 deletions

View File

@ -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);
}
}
}

View File

@ -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;
/// <summary>
/// unity的c#实现有bug,以接口类型保存的monobehaviour引用,!=和==运算符没有调用到monobehaviour重写过的运算符
/// 但是Equals方法可以,所以,这个接口判断为空请使用Equals
/// </summary>
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();

View File

@ -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<RomFile> 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);
}
}

View File

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

View File

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

View File

@ -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;
@ -27,22 +28,15 @@ namespace AxibugEmuOnline.Client
{
base.Awake();
Eventer.Instance.RegisterEvent<int>(EEvent.OnRoomListSingleUpdate, OnRoomSingleUpdate);
Eventer.Instance.RegisterEvent<int>(EEvent.OnRoomListSingleUpdate, OnRoomSignelUpdate);
}
protected override void OnDestroy()
private void OnRoomSignelUpdate(int roomID)
{
Eventer.Instance.UnregisterEvent<int>(EEvent.OnRoomListSingleUpdate, OnRoomSingleUpdate);
}
if (this.roomID != roomID) return;
private void OnRoomSingleUpdate(int roomId)
{
if (roomId != roomID) return;
if (App.roomMgr.GetRoomListMiniInfo(roomId, out var roomInfo))
{
if (App.roomMgr.GetRoomListMiniInfo(roomID, out var roomInfo))
UpdateUI(roomInfo);
}
}
public void SetData(object data)
@ -53,6 +47,20 @@ namespace AxibugEmuOnline.Client
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)
{
var hostNick = roomInfo.GetHostNickName();
@ -60,12 +68,12 @@ namespace AxibugEmuOnline.Client
SetBaseInfo(string.Empty, $"<b>{hostNick}</b>µÄ·¿¼ä - {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);

View File

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

View File

@ -38,11 +38,11 @@ namespace AxibugEmuOnline.Client
}
private static Dictionary<int, RomFile> s_RomFileCahcesInRoomInfo = new Dictionary<int, RomFile>();
public static void FetchRomFileInRoomInfo(this Protobuf_Room_MiniInfo roomInfo, EnumPlatform platform, Action<RomFile> callback)
public static void FetchRomFileInRoomInfo(this Protobuf_Room_MiniInfo roomInfo, EnumPlatform platform, Action<Protobuf_Room_MiniInfo, RomFile> 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;
}