versionflow autorelease机制优化,下一帧执行卸载

This commit is contained in:
ALIENJACK\alien 2025-08-19 17:13:54 +08:00
parent 886e884958
commit 712b303858

View File

@ -34,6 +34,8 @@ namespace VersionFlow.Runtime
internal BundleManager(BundleManifest local, BundleManifest remote)
{
VersionFlowX.BeginCoroutine(AutoReleaseCoroutine());
//初始化BundleManager
Stopwatch sw = Stopwatch.StartNew();
@ -88,7 +90,24 @@ namespace VersionFlow.Runtime
VersionFlowX.Log($"创建资源清单耗时:{sw.Elapsed.Milliseconds}ms");
}
internal BundleManager() { }
internal BundleManager()
{
VersionFlowX.BeginCoroutine(AutoReleaseCoroutine());
}
IEnumerator AutoReleaseCoroutine()
{
while (true)
{
if (VersionFlowX.Setting.AutoReleaseBundle && m_unloadDirty)
{
m_unloadDirty = false;
TryUnLoadBundles();
}
yield return null;
}
}
internal ABEntity GetEntityByAssetPath(string assetPath)
{
@ -351,6 +370,7 @@ namespace VersionFlow.Runtime
return request;
}
bool m_unloadDirty = false;
public void ReleaseAsset<T>(ref T asset) where T : UnityEngine.Object
{
if (!VersionFlowX.Setting.Enable)
@ -366,8 +386,10 @@ namespace VersionFlow.Runtime
asset = null;
if (VersionFlowX.Setting.AutoReleaseBundle)
TryUnLoadBundles();
if (!m_unloadDirty && VersionFlowX.Setting.AutoReleaseBundle)
{
m_unloadDirty = true;
}
}
}
public void ReleaseAsset<T>(IList<T> assetList) where T : UnityEngine.Object