From 02827ce3b84f39cbd5d633a19c39cd458abbcc42 Mon Sep 17 00:00:00 2001
From: ALEXTANG <574809918@qq.com>
Date: Tue, 28 Nov 2023 19:36:26 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96/=E6=96=B0=E5=A2=9E=E8=B6=85?=
=?UTF-8?q?=E7=89=9B=E9=80=BC=E4=B8=94=E5=BE=88=E6=96=B9=E4=BE=BF=E4=BD=BF?=
=?UTF-8?q?=E7=94=A8=E7=9A=84=E5=AF=B9=E8=B1=A1=E6=B1=A0=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
优化/新增超牛逼且很方便使用的对象池。
---
.../AssetRaw/Configs/need_cache_list.json | 16 ++++++++++
.../Configs/need_cache_list.json.meta | 7 ++++
.../ResourceModule/Pool/ResourceCacheMgr.cs | 32 +++++++++++++++++++
.../Modules/ResourceModule/ResourceModule.cs | 9 +++++-
4 files changed, 63 insertions(+), 1 deletion(-)
create mode 100644 UnityProject/Assets/AssetRaw/Configs/need_cache_list.json
create mode 100644 UnityProject/Assets/AssetRaw/Configs/need_cache_list.json.meta
diff --git a/UnityProject/Assets/AssetRaw/Configs/need_cache_list.json b/UnityProject/Assets/AssetRaw/Configs/need_cache_list.json
new file mode 100644
index 00000000..54ea47bc
--- /dev/null
+++ b/UnityProject/Assets/AssetRaw/Configs/need_cache_list.json
@@ -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
+ }
+]
\ No newline at end of file
diff --git a/UnityProject/Assets/AssetRaw/Configs/need_cache_list.json.meta b/UnityProject/Assets/AssetRaw/Configs/need_cache_list.json.meta
new file mode 100644
index 00000000..4939540e
--- /dev/null
+++ b/UnityProject/Assets/AssetRaw/Configs/need_cache_list.json.meta
@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: c9f7d9280641e9a4b87697ace96a4315
+TextScriptImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/Pool/ResourceCacheMgr.cs b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/Pool/ResourceCacheMgr.cs
index c1e49f3c..b41e9174 100644
--- a/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/Pool/ResourceCacheMgr.cs
+++ b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/Pool/ResourceCacheMgr.cs
@@ -45,6 +45,34 @@ namespace TEngine
/// 持久化的资源起始路径。存在这个路径开始的资源不会释放。
public void RegPersistResPath(List resList) => _needPersistResList.AddRange((IEnumerable)resList);
+ public void InitDefaultCachePool()
+ {
+ if (!ResourceManager.EnableGoPool)
+ {
+ return;
+ }
+
+ string assetLocation = "need_cache_list";
+
+ GameModule.Resource.LoadAssetAsync(assetLocation, handle =>
+ {
+ if (handle.AssetObject == null)
+ {
+ return;
+ }
+ TextAsset textAsset = handle.AssetObject as TextAsset;
+ if (textAsset == null)
+ {
+ return;
+ }
+ List list = Utility.Json.ToObject>(textAsset.text);
+ foreach (var config in list)
+ {
+ Instance.RegCacheResPath(config.ResPath, config.CacheTime, config.MaxPoolCnt, config.PoolGoFreeTime, config.MinPoolCnt);
+ }
+ });
+ }
+
///
/// 注册缓存池的资源。
///
@@ -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));
}
diff --git a/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceModule.cs b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceModule.cs
index df6f0d21..e29bf8f7 100644
--- a/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceModule.cs
+++ b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceModule.cs
@@ -234,7 +234,14 @@ namespace TEngine
///
public InitializationOperation InitPackage(string customPackageName = "")
{
- return m_ResourceManager.InitPackage(customPackageName);
+ InitializationOperation operation = m_ResourceManager.InitPackage(customPackageName);
+
+ operation.Completed += _ =>
+ {
+ ResourceCacheMgr.Instance.InitDefaultCachePool();
+ };
+
+ return operation;
}
///