拓展自定义鲁班加载配置,支持懒加载 默认使用懒加载,未使用的配置不会载入内存

拓展自定义鲁班加载配置,支持懒加载 默认使用懒加载,未使用的配置不会载入内存
This commit is contained in:
ALEXTANG
2023-08-17 23:07:07 +08:00
parent bf73ce333b
commit e071c20214
17 changed files with 1123 additions and 216 deletions

View File

@@ -7,12 +7,12 @@ using UnityEngine;
/// <summary>
/// 配置加载器。
/// </summary>
public class ConfigLoader:Singleton<ConfigLoader>
public class ConfigLoader : Singleton<ConfigLoader>
{
private bool _init = false;
private Tables _tables;
public Tables Tables
{
get
@@ -21,6 +21,7 @@ public class ConfigLoader:Singleton<ConfigLoader>
{
Load();
}
return _tables;
}
}
@@ -30,7 +31,7 @@ public class ConfigLoader:Singleton<ConfigLoader>
/// </summary>
public void Load()
{
_tables = new Tables(LoadByteBuf);
_tables = new Tables(LoadIdxByteBuf, LoadByteBuf);
_init = true;
}
@@ -41,7 +42,19 @@ public class ConfigLoader:Singleton<ConfigLoader>
/// <returns>ByteBuf</returns>
private ByteBuf LoadByteBuf(string file)
{
var textAssets = GameModule.Resource.LoadAsset<TextAsset>($"{SettingsUtils.FrameworkGlobalSettings.ConfigFolderName}{file}.bytes");
var textAssets = GameModule.Resource.LoadAsset<TextAsset>(file);
byte[] ret = textAssets.bytes;
return new ByteBuf(ret);
}
/// <summary>
/// 加载懒加载Index。
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
private ByteBuf LoadIdxByteBuf(string file)
{
var textAssets = GameModule.Resource.LoadAsset<TextAsset>($"Idx_{file}");
byte[] ret = textAssets.bytes;
return new ByteBuf(ret);
}
@@ -49,16 +62,11 @@ public class ConfigLoader:Singleton<ConfigLoader>
public class ConfigSystem : BaseLogicSys<ConfigSystem>
{
public Tables Tables => ConfigLoader.Instance.Tables;
public override bool OnInit()
{
Log.Warning("ConfigSystem OnInit");
InitConfig();
return base.OnInit();
}
private void InitConfig()
{
ConfigLoader.Instance.Load();
}
}
}