优化/新增超牛逼且很方便使用的对象池。

优化/新增超牛逼且很方便使用的对象池。
This commit is contained in:
ALEXTANG
2023-11-28 19:36:26 +08:00
parent 1a0e3f91e0
commit 02827ce3b8
4 changed files with 63 additions and 1 deletions

View File

@@ -0,0 +1,16 @@
[
{
"ResPath": "Assets/AssetRaw/Effects",
"CacheTime": 300,
"MaxPoolCnt": 30,
"PoolGoFreeTime": 300,
"MinPoolCnt": 0
},
{
"ResPath": "Assets/AssetRaw/PoolObjects/",
"CacheTime": 300,
"MaxPoolCnt": 30,
"PoolGoFreeTime": 300,
"MinPoolCnt": 0
}
]

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: c9f7d9280641e9a4b87697ace96a4315
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -45,6 +45,34 @@ namespace TEngine
/// <param name="resList">持久化的资源起始路径。存在这个路径开始的资源不会释放。</param>
public void RegPersistResPath(List<string> resList) => _needPersistResList.AddRange((IEnumerable<string>)resList);
public void InitDefaultCachePool()
{
if (!ResourceManager.EnableGoPool)
{
return;
}
string assetLocation = "need_cache_list";
GameModule.Resource.LoadAssetAsync<TextAsset>(assetLocation, handle =>
{
if (handle.AssetObject == null)
{
return;
}
TextAsset textAsset = handle.AssetObject as TextAsset;
if (textAsset == null)
{
return;
}
List<ResourceCacheConfig> list = Utility.Json.ToObject<List<ResourceCacheConfig>>(textAsset.text);
foreach (var config in list)
{
Instance.RegCacheResPath(config.ResPath, config.CacheTime, config.MaxPoolCnt, config.PoolGoFreeTime, config.MinPoolCnt);
}
});
}
/// <summary>
/// 注册缓存池的资源。
/// </summary>
@@ -61,6 +89,10 @@ namespace TEngine
int poolGoFreeTime = 120,
int minPoolCnt = 0)
{
if (_enableLog)
{
Log.Warning($"RegCacheResPath: {resPath} cacheTime: {cacheTime} maxPoolCnt: {maxPoolCnt} poolGoFreeTime: {poolGoFreeTime} minPoolCnt: {minPoolCnt}");
}
_needCacheResList.Add(new ResourceCacheConfig(resPath, cacheTime, maxPoolCnt, poolGoFreeTime, minPoolCnt));
}

View File

@@ -234,7 +234,14 @@ namespace TEngine
/// <returns></returns>
public InitializationOperation InitPackage(string customPackageName = "")
{
return m_ResourceManager.InitPackage(customPackageName);
InitializationOperation operation = m_ResourceManager.InitPackage(customPackageName);
operation.Completed += _ =>
{
ResourceCacheMgr.Instance.InitDefaultCachePool();
};
return operation;
}
/// <summary>