diff --git a/AxibugEmuOnline.Client/Assets/Script/AppAxibugEmuOnline.cs b/AxibugEmuOnline.Client/Assets/Script/AppAxibugEmuOnline.cs index 1f45603c..62113409 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppAxibugEmuOnline.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppAxibugEmuOnline.cs @@ -1,6 +1,7 @@ using AxibugEmuOnline.Client.Manager; using AxibugEmuOnline.Client.Network; using System; +using System.Collections; using UnityEngine; using static AxibugEmuOnline.Client.Manager.LogManager; @@ -19,8 +20,13 @@ namespace AxibugEmuOnline.Client.ClientCore public static UserDataManager user; public static AppNetGame netgame; public static AppEmu emu; - - public static void Init() + public static RomLib romLib; + public static HttpAPI httpAPI; + + private static CoroutineRunner coRunner; + + [RuntimeInitializeOnLoadMethod] + static void Init() { log = new LogManager(); LogManager.OnLog += OnNoSugarNetLog; @@ -30,6 +36,20 @@ namespace AxibugEmuOnline.Client.ClientCore user = new UserDataManager(); emu = new AppEmu(); netgame = new AppNetGame(); + + var go = new GameObject("[AppAxibugEmuOnline]"); + GameObject.DontDestroyOnLoad(go); + coRunner = go.AddComponent(); + } + + public static Coroutine StartCoroutine(IEnumerator itor) + { + return coRunner.StartCoroutine(itor); + } + + public static void StopCoroutine(Coroutine cor) + { + coRunner.StopCoroutine(cor); } public static bool Connect(string IP, int port) @@ -43,7 +63,7 @@ namespace AxibugEmuOnline.Client.ClientCore } static void OnNoSugarNetLog(int LogLevel, string msg) { - Debug.Log("[AxibugEmuOnline]:"+msg); + Debug.Log("[AxibugEmuOnline]:" + msg); } } } \ No newline at end of file diff --git a/AxibugEmuOnline.Client/Assets/Script/Manager/CoroutineRunner.cs b/AxibugEmuOnline.Client/Assets/Script/Manager/CoroutineRunner.cs new file mode 100644 index 00000000..c6541b8d --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/Manager/CoroutineRunner.cs @@ -0,0 +1,8 @@ +using UnityEngine; + +namespace AxibugEmuOnline.Client +{ + public class CoroutineRunner : MonoBehaviour + { + } +} diff --git a/AxibugEmuOnline.Client/Assets/Script/Manager/CoroutineRunner.cs.meta b/AxibugEmuOnline.Client/Assets/Script/Manager/CoroutineRunner.cs.meta new file mode 100644 index 00000000..7ae66eeb --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/Manager/CoroutineRunner.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 26e0101eb56737b4f97fcaa3bd319d43 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AxibugEmuOnline.Client/Assets/Script/Manager/HttpAPI.cs b/AxibugEmuOnline.Client/Assets/Script/Manager/HttpAPI.cs new file mode 100644 index 00000000..2d896ca6 --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/Manager/HttpAPI.cs @@ -0,0 +1,51 @@ +using AxibugEmuOnline.Client.ClientCore; +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.Networking; + +namespace AxibugEmuOnline.Client +{ + public class HttpAPI + { + public string WebSite = "http://emu.axibug.com/api"; + + public void GetNesRomList(Action callback, int page, int pageSize = 10) + { + AppAxibugEmuOnline.StartCoroutine(GetNesRomListFlow(page, pageSize, callback)); + } + + private IEnumerator GetNesRomListFlow(int page, int pageSize, Action callback) + { + UnityWebRequest request = new UnityWebRequest($"{WebSite}/NesRomList?Page={page}&PageSize={pageSize}"); + yield return request.SendWebRequest(); + + if (request.result != UnityWebRequest.Result.Success) + { + callback.Invoke(null); + yield break; + } + + var resp = JsonUtility.FromJson(request.downloadHandler.text); + callback.Invoke(resp); + } + + public class Resp_GameList + { + public int Page { get; set; } + public int MaxPage { get; set; } + public int ResultAllCount { get; set; } + public List GameList { get; set; } + } + + public class Resp_RomInfo + { + public int ID { get; set; } + public string Hash { get; set; } + public string RomName { get; set; } + public string Url { get; set; } + public string ImgUrl { get; set; } + } + } +} diff --git a/AxibugEmuOnline.Client/Assets/Script/Manager/HttpAPI.cs.meta b/AxibugEmuOnline.Client/Assets/Script/Manager/HttpAPI.cs.meta new file mode 100644 index 00000000..078f3095 --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/Manager/HttpAPI.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 81bb136dc2c85304db4715953f751aa6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib.meta b/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib.meta new file mode 100644 index 00000000..a783f447 --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 006d5604a1d73de4e8d057974313dbaf +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/EnumPlatform.cs b/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/EnumPlatform.cs new file mode 100644 index 00000000..d2c8aa5e --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/EnumPlatform.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AxibugEmuOnline.Client +{ + public enum EnumPlatform + { + NES + } +} diff --git a/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/EnumPlatform.cs.meta b/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/EnumPlatform.cs.meta new file mode 100644 index 00000000..89840290 --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/EnumPlatform.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 355fa00c125158f4ba90003b0fd5d788 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/RomFile.cs b/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/RomFile.cs new file mode 100644 index 00000000..baf0957c --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/RomFile.cs @@ -0,0 +1,46 @@ +using System; +using System.IO; +using UnityEngine; + +namespace AxibugEmuOnline.Client +{ + public class RomFile + { + private HttpAPI.Resp_RomInfo webData; + private bool hasLocalFile; + private string romName; + private EnumPlatform platform; + + public string LocalFilePath => $"{Application.persistentDataPath}/RemoteRoms/{platform}/{romName}"; + + + public RomFile(EnumPlatform platform) + { + this.platform = platform; + } + + public void GetRomFileData(Action callback) + { + if (webData == null) { callback.Invoke(null); return; } + if (hasLocalFile) + { + var path = LocalFilePath; + } + } + + public void SetWebData(HttpAPI.Resp_RomInfo resp_RomInfo) + { + webData = resp_RomInfo; + romName = Path.GetFileName(webData.Url); + + if (File.Exists(LocalFilePath)) + { + hasLocalFile = true; + } + else + { + hasLocalFile = false; + } + } + } +} diff --git a/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/RomFile.cs.meta b/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/RomFile.cs.meta new file mode 100644 index 00000000..f8eb0324 --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/RomFile.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3a876afb939308548a7b4bdc53a3f6df +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/RomLib.cs b/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/RomLib.cs new file mode 100644 index 00000000..f2988a6e --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/RomLib.cs @@ -0,0 +1,44 @@ +using AxibugEmuOnline.Client.ClientCore; +using System; +using System.Collections.Generic; + +namespace AxibugEmuOnline.Client +{ + public class RomLib + { + private List nesRomFiles = new List(); + + public void GetNesRomFile(int index, Action callback) + { + if (nesRomFiles.Count <= index) + { + int pageSize = 10; + int page = index / pageSize; + int indexInPage = index % page; + + //填充空的RomFile数据 + var needFill = index - nesRomFiles.Count + 1; + needFill += pageSize - indexInPage - 1; + for (int i = 0; i < needFill; i++) + { + nesRomFiles.Add(new RomFile(EnumPlatform.NES)); + } + + AppAxibugEmuOnline.httpAPI.GetNesRomList((romList) => + { + if (romList == null) + { + callback.Invoke(null); + } + else + { + for (int i = 0; i < romList.GameList.Count; i++) + { + nesRomFiles[pageSize * (page - 1) + i].SetWebData(romList.GameList[i]); + } + } + }, page, pageSize); + } + } + } +} diff --git a/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/RomLib.cs.meta b/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/RomLib.cs.meta new file mode 100644 index 00000000..b4a2ea56 --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/RomLib.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8b1860dd3aacece40a93ae8273fc71b1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: