97 lines
2.4 KiB
C#
97 lines
2.4 KiB
C#
using System.Collections;
|
|
using System.IO;
|
|
using cfg;
|
|
using Cysharp.Threading.Tasks;
|
|
using PhxhSDK;
|
|
using SimpleJSON;
|
|
using UnityEngine;
|
|
|
|
|
|
namespace Framework
|
|
{
|
|
public class TableManager : Singlenton<TableManager>, IInitable, ILoadable
|
|
{
|
|
private Tables _tables;
|
|
public Tables Tables
|
|
{
|
|
get
|
|
{
|
|
#if UNITY_EDITOR
|
|
if (_tables == null)
|
|
{
|
|
_tables = EditorTableManager.instance.tables;
|
|
}
|
|
#endif
|
|
return _tables;
|
|
}
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
}
|
|
|
|
public void Release()
|
|
{
|
|
}
|
|
|
|
public static JSONNode LoadByteBuf(string file)
|
|
{
|
|
// DebugUtil.LogY("TableManager LoadByteBuf {0}", file);
|
|
var filePath = _CombinePath(file);
|
|
var loadAsset = AssetManager.Instance.GetPreLoadResult<TextAsset>(filePath);
|
|
var jsonText = loadAsset.text;
|
|
return JSON.Parse(jsonText);
|
|
}
|
|
|
|
private static string _CombinePath(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 = _CombinePath(fileName);
|
|
AssetManager.Instance.Unload(fullPath);
|
|
}
|
|
|
|
private void _PostPreload(string fileName)
|
|
{
|
|
var fullPath = _CombinePath(fileName);
|
|
AssetManager.Instance.PostPreload(fullPath);
|
|
}
|
|
|
|
public UniTask Unload()
|
|
{
|
|
return UniTask.NextFrame();
|
|
}
|
|
}
|
|
}
|