NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Framework/Data/TableManager.cs

85 lines
2.2 KiB
C#
Raw Normal View History

2023-08-22 19:08:45 +08:00
using System.Collections;
using System.IO;
using cfg;
using Cysharp.Threading.Tasks;
2023-10-19 15:00:19 +08:00
using PhxhSDK;
2023-08-22 19:08:45 +08:00
using SimpleJSON;
using UnityEngine;
namespace Framework
{
2023-10-19 15:00:19 +08:00
public class TableManager : Singlenton<TableManager>, IInitable, ILoadable
2023-08-22 19:08:45 +08:00
{
2023-10-19 15:00:19 +08:00
private Tables _tables;
2023-08-22 19:08:45 +08:00
public Tables Tables => _tables;
public void Init()
{
}
public void Release()
{
}
public static JSONNode LoadByteBuf(string file)
{
2023-12-14 18:25:52 +08:00
// DebugUtil.LogY("TableManager LoadByteBuf {0}", file);
2023-08-22 19:08:45 +08:00
var filePath = _CombiePath(file);
2024-02-05 14:45:46 +08:00
var loadAsset = AssetManager.Instance.GetPreLoadResult<TextAsset>(filePath);
2023-08-22 19:08:45 +08:00
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()
{
2023-10-19 15:00:19 +08:00
try
{
2023-11-27 15:27:20 +08:00
if (_tables != null)
{
return;
}
2023-10-19 15:00:19 +08:00
// 先预加载
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}");
}
2023-08-22 19:08:45 +08:00
}
2023-11-27 15:27:20 +08:00
public void UnLoad()
{
}
2023-08-22 19:08:45 +08:00
private void _UnlockJson(string fileName)
{
var fullPath = _CombiePath(fileName);
2023-10-19 15:00:19 +08:00
AssetManager.Instance.Unload(fullPath);
2023-08-22 19:08:45 +08:00
}
private void _PostPreload(string fileName)
{
var fullPath = _CombiePath(fileName);
2023-10-19 15:00:19 +08:00
AssetManager.Instance.PostPreload(fullPath);
2023-08-22 19:08:45 +08:00
}
public UniTask Unload()
{
return UniTask.NextFrame();
}
}
}