From 1aaa46c82c6054f4eff48dc930dfb3c2c48d68ba Mon Sep 17 00:00:00 2001
From: ALEXTANG <574809918@qq.com>
Date: Thu, 20 Jun 2024 09:42:49 +0800
Subject: [PATCH] =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=A8=A1=E5=9D=97=E5=A2=9E?=
=?UTF-8?q?=E5=8A=A0=E8=AE=BE=E7=BD=AE=EF=BC=9A=E6=98=AF=E5=90=A6=E4=BD=BF?=
=?UTF-8?q?=E7=94=A8=E7=B3=BB=E7=BB=9F=E9=87=8A=E6=94=BE=E6=97=A0=E7=94=A8?=
=?UTF-8?q?=E8=B5=84=E6=BA=90=E7=AD=96=E7=95=A5=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
资源模块增加设置:是否使用系统释放无用资源策略。
---
.../Editor/Inspector/ResourceModuleInspector.cs | 4 ++++
.../Modules/ResourceModule/ResourceModule.cs | 14 ++++++++++++++
2 files changed, 18 insertions(+)
diff --git a/UnityProject/Assets/TEngine/Editor/Inspector/ResourceModuleInspector.cs b/UnityProject/Assets/TEngine/Editor/Inspector/ResourceModuleInspector.cs
index bfc0af299..abe51a2ac 100644
--- a/UnityProject/Assets/TEngine/Editor/Inspector/ResourceModuleInspector.cs
+++ b/UnityProject/Assets/TEngine/Editor/Inspector/ResourceModuleInspector.cs
@@ -30,6 +30,7 @@ internal sealed class ResourceModuleInspector : GameFrameworkInspector
private SerializedProperty m_ReadWritePathType = null;
private SerializedProperty m_MinUnloadUnusedAssetsInterval = null;
private SerializedProperty m_MaxUnloadUnusedAssetsInterval = null;
+ private SerializedProperty m_UseSystemUnloadUnusedAssets = null;
private SerializedProperty m_AssetAutoReleaseInterval = null;
private SerializedProperty m_AssetCapacity = null;
private SerializedProperty m_AssetExpireTime = null;
@@ -106,6 +107,8 @@ public override void OnInspectorGUI()
}
}
+ EditorGUILayout.PropertyField(m_UseSystemUnloadUnusedAssets);
+
float minUnloadUnusedAssetsInterval =
EditorGUILayout.Slider("Min Unload Unused Assets Interval", m_MinUnloadUnusedAssetsInterval.floatValue, 0f, 3600f);
if (Math.Abs(minUnloadUnusedAssetsInterval - m_MinUnloadUnusedAssetsInterval.floatValue) > 0.01f)
@@ -246,6 +249,7 @@ private void OnEnable()
m_ReadWritePathType = serializedObject.FindProperty("m_ReadWritePathType");
m_MinUnloadUnusedAssetsInterval = serializedObject.FindProperty("m_MinUnloadUnusedAssetsInterval");
m_MaxUnloadUnusedAssetsInterval = serializedObject.FindProperty("m_MaxUnloadUnusedAssetsInterval");
+ m_UseSystemUnloadUnusedAssets = serializedObject.FindProperty("m_UseSystemUnloadUnusedAssets");
m_AssetAutoReleaseInterval = serializedObject.FindProperty("m_AssetAutoReleaseInterval");
m_AssetCapacity = serializedObject.FindProperty("m_AssetCapacity");
m_AssetExpireTime = serializedObject.FindProperty("m_AssetExpireTime");
diff --git a/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceModule.cs b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceModule.cs
index 72b21d92e..fbc87b45a 100644
--- a/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceModule.cs
+++ b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceModule.cs
@@ -32,6 +32,7 @@ public class ResourceModule : Module
[SerializeField] private float m_MaxUnloadUnusedAssetsInterval = 300f;
+ [SerializeField] private bool m_UseSystemUnloadUnusedAssets = true;
///
/// 当前最新的包裹版本。
///
@@ -157,6 +158,15 @@ public float MaxUnloadUnusedAssetsInterval
get => m_MaxUnloadUnusedAssetsInterval;
set => m_MaxUnloadUnusedAssetsInterval = value;
}
+
+ ///
+ /// 使用系统释放无用资源策略。
+ ///
+ public bool UseSystemUnloadUnusedAssets
+ {
+ get => m_UseSystemUnloadUnusedAssets;
+ set => m_UseSystemUnloadUnusedAssets = value;
+ }
///
/// 获取无用资源释放的等待时长,以秒为单位。
@@ -680,6 +690,10 @@ private void Update()
m_PreorderUnloadUnusedAssets = false;
m_LastUnloadUnusedAssetsOperationElapseSeconds = 0f;
m_AsyncOperation = Resources.UnloadUnusedAssets();
+ if (m_UseSystemUnloadUnusedAssets)
+ {
+ m_ResourceManager.UnloadUnusedAssets();
+ }
}
if (m_AsyncOperation is { isDone: true })