mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
拓展自定义鲁班加载配置,支持UniTask异步 默认使用同步加载
拓展自定义鲁班加载配置,支持UniTask异步 默认使用同步加载
This commit is contained in:
64
Luban/CustomTemplate_Client/ConfigLoader.cs
Normal file
64
Luban/CustomTemplate_Client/ConfigLoader.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using Bright.Serialization;
|
||||
using GameBase;
|
||||
using GameConfig;
|
||||
using TEngine;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 配置加载器。
|
||||
/// </summary>
|
||||
public class ConfigLoader:Singleton<ConfigLoader>
|
||||
{
|
||||
private bool _init = false;
|
||||
|
||||
private Tables _tables;
|
||||
|
||||
public Tables Tables
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_init)
|
||||
{
|
||||
Load();
|
||||
}
|
||||
return _tables;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载配置。
|
||||
/// </summary>
|
||||
public void Load()
|
||||
{
|
||||
_tables = new Tables(LoadByteBuf);
|
||||
_init = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载二进制配置。
|
||||
/// </summary>
|
||||
/// <param name="file">FileName</param>
|
||||
/// <returns>ByteBuf</returns>
|
||||
private ByteBuf LoadByteBuf(string file)
|
||||
{
|
||||
var textAssets = GameModule.Resource.LoadAsset<TextAsset>($"{SettingsUtils.FrameworkGlobalSettings.ConfigFolderName}{file}.bytes");
|
||||
byte[] ret = textAssets.bytes;
|
||||
return new ByteBuf(ret);
|
||||
}
|
||||
}
|
||||
|
||||
public class ConfigSystem : BaseLogicSys<ConfigSystem>
|
||||
{
|
||||
public override bool OnInit()
|
||||
{
|
||||
Log.Warning("ConfigSystem OnInit");
|
||||
InitConfig();
|
||||
return base.OnInit();
|
||||
}
|
||||
|
||||
private void InitConfig()
|
||||
{
|
||||
ConfigLoader.Instance.Load();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user