update resource manager

增加卸载指定资源的方法。
This commit is contained in:
hevinci
2023-10-19 16:28:30 +08:00
parent 82ef993d83
commit 194afe435a
9 changed files with 208 additions and 37 deletions

View File

@@ -105,7 +105,7 @@ namespace YooAsset
for (int i = _loaderList.Count - 1; i >= 0; i--)
{
BundleLoaderBase loader = _loaderList[i];
loader.TryDestroyAllProviders();
loader.TryDestroyProviders();
}
for (int i = _loaderList.Count - 1; i >= 0; i--)
@@ -121,6 +121,50 @@ namespace YooAsset
}
}
/// <summary>
/// 尝试卸载指定资源的资源包(包括依赖资源)
/// </summary>
public void TryUnloadUnusedAsset(AssetInfo assetInfo)
{
if (assetInfo.IsInvalid)
{
YooLogger.Error($"Failed to unload asset ! {assetInfo.Error}");
return;
}
// 卸载主资源包加载器
string manBundleName = _bundleQuery.GetMainBundleName(assetInfo);
var mainLoader = TryGetAssetBundleLoader(manBundleName);
if (mainLoader != null)
{
mainLoader.TryDestroyProviders();
if (mainLoader.CanDestroy())
{
string bundleName = mainLoader.MainBundleInfo.Bundle.BundleName;
mainLoader.Destroy();
_loaderList.Remove(mainLoader);
_loaderDic.Remove(bundleName);
}
}
// 卸载依赖资源包加载器
string[] dependBundleNames = _bundleQuery.GetDependBundleNames(assetInfo);
foreach (var dependBundleName in dependBundleNames)
{
var dependLoader = TryGetAssetBundleLoader(dependBundleName);
if (dependLoader != null)
{
if (dependLoader.CanDestroy())
{
string bundleName = dependLoader.MainBundleInfo.Bundle.BundleName;
dependLoader.Destroy();
_loaderList.Remove(dependLoader);
_loaderDic.Remove(bundleName);
}
}
}
}
/// <summary>
/// 强制回收所有资源
/// </summary>
@@ -357,9 +401,9 @@ namespace YooAsset
}
return result;
}
internal void RemoveBundleProviders(List<ProviderBase> providers)
internal void RemoveBundleProviders(List<ProviderBase> removeList)
{
foreach (var provider in providers)
foreach (var provider in removeList)
{
_providerList.Remove(provider);
_providerDic.Remove(provider.ProviderGUID);