mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
优化/新增超牛逼且很方便使用的对象池。
优化/新增超牛逼且很方便使用的对象池。
This commit is contained in:
16
UnityProject/Assets/AssetRaw/Configs/need_cache_list.json
Normal file
16
UnityProject/Assets/AssetRaw/Configs/need_cache_list.json
Normal 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
|
||||
}
|
||||
]
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9f7d9280641e9a4b87697ace96a4315
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -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));
|
||||
}
|
||||
|
||||
|
@@ -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>
|
||||
|
Reference in New Issue
Block a user