using System.Collections; using System.IO; using cfg; using Cysharp.Threading.Tasks; using PhxhSDK; using SimpleJSON; using UnityEngine; namespace Framework { public class TableManager : Singlenton, IInitable, ILoadable { private Tables _tables; public Tables Tables => _tables; public void Init() { } public void Release() { } public static JSONNode LoadByteBuf(string file) { // DebugUtil.LogY("TableManager LoadByteBuf {0}", file); var filePath = _CombiePath(file); var loadAsset = AssetManager.Instance.LoadAsset(filePath); var jsonText = loadAsset.text; return JSON.Parse(jsonText); } private static string _CombiePath(string fileName) { return string.Format(Constants.DATA_FORMAT_PATH, fileName); } public async UniTask Load() { try { if (_tables != null) { return; } // 先预加载 Tables.PostPreload(_PostPreload); await AssetManager.Instance.WaitAllPreloads(); // 再加载 _tables = new Tables(LoadByteBuf); // 再释放 Tables.AfterLoaded(_UnlockJson); EventManager.Instance.Send(EventManager.EventName.AllConfigLoad); } catch (System.Exception e) { DebugUtil.LogError($"Load Failed,exception:{e.Message} \n {e.StackTrace}"); } } public void UnLoad() { } private void _UnlockJson(string fileName) { var fullPath = _CombiePath(fileName); AssetManager.Instance.Unload(fullPath); } private void _PostPreload(string fileName) { var fullPath = _CombiePath(fileName); AssetManager.Instance.PostPreload(fullPath); } public UniTask Unload() { return UniTask.NextFrame(); } } }