2023-08-22 19:08:45 +08:00
|
|
|
using System.Collections;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using cfg;
|
2024-06-20 16:06:27 +08:00
|
|
|
using cfg.MaskCfg;
|
2023-08-22 19:08:45 +08:00
|
|
|
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;
|
2024-03-06 14:45:58 +08:00
|
|
|
public Tables Tables
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
#if UNITY_EDITOR
|
2024-03-12 19:10:08 +08:00
|
|
|
if (_tables == null && !Application.isPlaying)
|
2024-03-06 14:45:58 +08:00
|
|
|
{
|
|
|
|
|
_tables = EditorTableManager.instance.tables;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
return _tables;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-22 19:08:45 +08:00
|
|
|
|
|
|
|
|
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);
|
2024-03-07 16:10:18 +08:00
|
|
|
var filePath = _CombinePath(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);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-07 16:10:18 +08:00
|
|
|
private static string _CombinePath(string fileName)
|
2023-08-22 19:08:45 +08:00
|
|
|
{
|
|
|
|
|
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);
|
2024-06-21 14:52:24 +08:00
|
|
|
await StringManager.LoadMixKeyDic();
|
2023-10-19 15:00:19 +08:00
|
|
|
// 再释放
|
|
|
|
|
Tables.AfterLoaded(_UnlockJson);
|
2024-06-20 16:06:27 +08:00
|
|
|
|
|
|
|
|
#region 屏蔽词
|
|
|
|
|
foreach (DataMask dataMask in Tables.MaskConfig.DataList)
|
|
|
|
|
{
|
|
|
|
|
MaskWord.SetWord(dataMask.Mask);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
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)
|
|
|
|
|
{
|
2024-03-07 16:10:18 +08:00
|
|
|
var fullPath = _CombinePath(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)
|
|
|
|
|
{
|
2024-03-07 16:10:18 +08:00
|
|
|
var fullPath = _CombinePath(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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|