diff --git a/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs b/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs
index 0d59827..bff8c87 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs
@@ -341,6 +341,14 @@ namespace YooAsset
_providers.Remove(provider);
}
}
+ internal bool CheckBundleCanDestroy(int bundleID)
+ {
+ string bundleName = BundleServices.GetBundleName(bundleID);
+ BundleLoaderBase loader = TryGetAssetBundleLoader(bundleName);
+ if (loader == null)
+ return true;
+ return loader.CanDestroy();
+ }
private BundleLoaderBase CreateAssetBundleLoaderInternal(BundleInfo bundleInfo)
{
diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/BundleLoaderBase.cs b/Assets/YooAsset/Runtime/AssetSystem/Loader/BundleLoaderBase.cs
index dc9ef22..6a3e54e 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/Loader/BundleLoaderBase.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/BundleLoaderBase.cs
@@ -122,6 +122,15 @@ namespace YooAsset
if (RefCount > _providers.Count)
return;
+ // 条件3:检查依赖链上的资源包
+ // 依赖该资源包的所有资源包可以销毁
+ // 注意:互相引用的资源包无法卸载!
+ foreach (var bundleID in MainBundleInfo.Bundle.ReferenceIDs)
+ {
+ if (Impl.CheckBundleCanDestroy(bundleID) == false)
+ return;
+ }
+
// 销毁所有Providers
foreach (var provider in _providers)
{
diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/DeserializeManifestOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/DeserializeManifestOperation.cs
index 364f8aa..8a2d3de 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/DeserializeManifestOperation.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/DeserializeManifestOperation.cs
@@ -143,6 +143,7 @@ namespace YooAsset
patchBundle.IsRawFile = _buffer.ReadBool();
patchBundle.LoadMethod = _buffer.ReadByte();
patchBundle.Tags = _buffer.ReadUTF8Array();
+ patchBundle.ReferenceIDs = _buffer.ReadInt32Array();
Manifest.BundleList.Add(patchBundle);
patchBundle.ParseBundle(Manifest.PackageName, Manifest.OutputNameStyle);
diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs b/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs
index 7e5e018..0d6a405 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs
@@ -41,7 +41,12 @@ namespace YooAsset
///
public string[] Tags;
+ ///
+ /// 引用该资源包的ID列表
+ ///
+ public int[] ReferenceIDs;
+
///
/// 所属的包裹名称
///
diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs b/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs
index d892b54..91edb02 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs
@@ -220,6 +220,22 @@ namespace YooAsset
}
}
+ ///
+ /// 获取资源包名称
+ ///
+ public string GetBundleName(int bundleID)
+ {
+ if (bundleID >= 0 && bundleID < BundleList.Count)
+ {
+ var patchBundle = BundleList[bundleID];
+ return patchBundle.BundleName;
+ }
+ else
+ {
+ throw new Exception($"Invalid bundle id : {bundleID}");
+ }
+ }
+
///
/// 尝试获取补丁资源
///
diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchManifestTools.cs b/Assets/YooAsset/Runtime/PatchSystem/PatchManifestTools.cs
index 10d93e7..7378aaf 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/PatchManifestTools.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/PatchManifestTools.cs
@@ -65,6 +65,7 @@ namespace YooAsset
buffer.WriteBool(patchBundle.IsRawFile);
buffer.WriteByte(patchBundle.LoadMethod);
buffer.WriteUTF8Array(patchBundle.Tags);
+ buffer.WriteInt32Array(patchBundle.ReferenceIDs);
}
// 写入文件流
@@ -127,6 +128,7 @@ namespace YooAsset
patchBundle.IsRawFile = buffer.ReadBool();
patchBundle.LoadMethod = buffer.ReadByte();
patchBundle.Tags = buffer.ReadUTF8Array();
+ patchBundle.ReferenceIDs = buffer.ReadInt32Array();
manifest.BundleList.Add(patchBundle);
}
}
diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorSimulateModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorSimulateModeImpl.cs
index 27e239f..ce57146 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorSimulateModeImpl.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorSimulateModeImpl.cs
@@ -95,6 +95,10 @@ namespace YooAsset
{
throw new NotImplementedException();
}
+ string IBundleServices.GetBundleName(int bundleID)
+ {
+ throw new NotImplementedException();
+ }
bool IBundleServices.IsServicesValid()
{
return _activeManifest != null;
diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs
index 53ecf73..1339fde 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs
@@ -330,6 +330,10 @@ namespace YooAsset
}
return result.ToArray();
}
+ string IBundleServices.GetBundleName(int bundleID)
+ {
+ return _activeManifest.GetBundleName(bundleID);
+ }
bool IBundleServices.IsServicesValid()
{
return _activeManifest != null;
diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs
index a89c751..5ce8832 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs
@@ -123,6 +123,10 @@ namespace YooAsset
}
return result.ToArray();
}
+ string IBundleServices.GetBundleName(int bundleID)
+ {
+ return _activeManifest.GetBundleName(bundleID);
+ }
bool IBundleServices.IsServicesValid()
{
return _activeManifest != null;
diff --git a/Assets/YooAsset/Runtime/Services/IBundleServices.cs b/Assets/YooAsset/Runtime/Services/IBundleServices.cs
index 253a014..75c8620 100644
--- a/Assets/YooAsset/Runtime/Services/IBundleServices.cs
+++ b/Assets/YooAsset/Runtime/Services/IBundleServices.cs
@@ -13,6 +13,11 @@ namespace YooAsset
///
BundleInfo[] GetAllDependBundleInfos(AssetInfo assetPath);
+ ///
+ /// 获取资源包名称
+ ///
+ string GetBundleName(int bundleID);
+
///
/// 服务接口是否有效
///
diff --git a/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs b/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs
index dac7ac6..2f91fe4 100644
--- a/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs
+++ b/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs
@@ -24,7 +24,7 @@ namespace YooAsset
///
/// 清单文件格式版本
///
- public const string PatchManifestFileVersion = "1.4.0";
+ public const string PatchManifestFileVersion = "1.4.6";
///