AxibugEmuOnline/AxibugEmuOnline.Client/Assets/Script/Manager/AppEmu.cs

83 lines
2.5 KiB
C#
Raw Normal View History

using AxibugEmuOnline.Client.ClientCore;
2024-11-08 11:31:12 +08:00
using AxibugEmuOnline.Client.Event;
using MyNes.Core;
2024-11-08 11:31:12 +08:00
using System;
using UnityEngine;
namespace AxibugEmuOnline.Client.Manager
2024-07-03 14:43:11 +08:00
{
2024-08-16 10:20:00 +08:00
public class AppEmu
2024-07-04 21:06:41 +08:00
{
2024-11-08 11:31:12 +08:00
/// <summary>
/// unity的c#实现有bug,以接口类型保存的monobehaviour引用,!=和==运算符没有调用到monobehaviour重写过的运算符
/// 但是Equals方法可以,所以,这个接口判断为空请使用Equals
/// </summary>
private IEmuCore m_emuCore;
2024-11-19 13:09:53 +08:00
/// <summary>
/// unity的c#实现有bug,以接口类型保存的monobehaviour引用,!=和==运算符没有调用到monobehaviour重写过的运算符
/// 但是Equals方法可以,所以,这个接口判断为空请使用Equals
/// </summary>
public IEmuCore Core => m_emuCore;
2024-09-14 15:32:29 +08:00
2024-11-08 11:31:12 +08:00
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)
{
2024-11-08 11:38:32 +08:00
if (!m_emuCore.IsNull()) return;
2024-08-16 10:20:00 +08:00
switch (romFile.Platform)
{
case EnumPlatform.NES:
m_emuCore = GameObject.Instantiate(Resources.Load<GameObject>("NES/NesEmulator")).GetComponent<IEmuCore>();
break;
}
m_emuCore.StartGame(romFile);
LaunchUI.Instance.HideMainMenu();
InGameUI.Instance.Show(romFile, m_emuCore);
m_emuCore.SetupScheme();
}
public void StopGame()
{
2024-11-08 11:31:12 +08:00
if (m_emuCore.IsNull()) return;
GameObject.Destroy(m_emuCore.gameObject);
m_emuCore = null;
2024-09-14 15:32:29 +08:00
InGameUI.Instance.Hide();
LaunchUI.Instance.ShowMainMenu();
}
2024-11-13 18:42:30 +08:00
public void ResetGame()
{
if(m_emuCore.IsNull()) return;
m_emuCore.DoReset();
}
2024-07-03 14:43:11 +08:00
}
}