Skip to content

Commit

Permalink
资源模块增加设置:是否使用系统释放无用资源策略。
Browse files Browse the repository at this point in the history
资源模块增加设置:是否使用系统释放无用资源策略。
  • Loading branch information
Alex-Rachel committed Jun 20, 2024
1 parent ca79adc commit 1aaa46c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class ResourceModule : Module

[SerializeField] private float m_MaxUnloadUnusedAssetsInterval = 300f;

[SerializeField] private bool m_UseSystemUnloadUnusedAssets = true;
/// <summary>
/// 当前最新的包裹版本。
/// </summary>
Expand Down Expand Up @@ -157,6 +158,15 @@ public float MaxUnloadUnusedAssetsInterval
get => m_MaxUnloadUnusedAssetsInterval;
set => m_MaxUnloadUnusedAssetsInterval = value;
}

/// <summary>
/// 使用系统释放无用资源策略。
/// </summary>
public bool UseSystemUnloadUnusedAssets
{
get => m_UseSystemUnloadUnusedAssets;
set => m_UseSystemUnloadUnusedAssets = value;
}

/// <summary>
/// 获取无用资源释放的等待时长,以秒为单位。
Expand Down Expand Up @@ -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 })
Expand Down

0 comments on commit 1aaa46c

Please sign in to comment.