2024-09-13 13:28:33 +08:00
|
|
|
|
using AxibugEmuOnline.Client.ClientCore;
|
2024-11-08 11:31:12 +08:00
|
|
|
|
using AxibugEmuOnline.Client.Event;
|
2024-11-07 17:58:20 +08:00
|
|
|
|
using MyNes.Core;
|
2024-11-08 11:31:12 +08:00
|
|
|
|
using System;
|
2024-09-13 13:28:33 +08:00
|
|
|
|
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>
|
2024-11-07 17:58:20 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-09-13 13:28:33 +08:00
|
|
|
|
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
|
|
|
|
|
2024-09-13 13:28:33 +08:00
|
|
|
|
switch (romFile.Platform)
|
|
|
|
|
{
|
|
|
|
|
case EnumPlatform.NES:
|
2024-11-07 17:58:20 +08:00
|
|
|
|
m_emuCore = GameObject.Instantiate(Resources.Load<GameObject>("NES/NesEmulator")).GetComponent<IEmuCore>();
|
2024-09-13 13:28:33 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2024-11-07 17:58:20 +08:00
|
|
|
|
|
|
|
|
|
m_emuCore.StartGame(romFile);
|
|
|
|
|
LaunchUI.Instance.HideMainMenu();
|
|
|
|
|
InGameUI.Instance.Show(romFile, m_emuCore);
|
|
|
|
|
|
|
|
|
|
m_emuCore.SetupScheme();
|
2024-09-13 13:28:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-13 13:28:33 +08:00
|
|
|
|
|
2024-09-14 15:32:29 +08:00
|
|
|
|
InGameUI.Instance.Hide();
|
|
|
|
|
LaunchUI.Instance.ShowMainMenu();
|
2024-11-07 17:58:20 +08:00
|
|
|
|
|
2024-11-21 20:32:41 +08:00
|
|
|
|
CommandDispatcher.Instance.Current = CommandDispatcher.Instance.Normal;
|
2024-09-13 13:28:33 +08:00
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
}
|