diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSLoadBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSLoadBundleOperation.cs
index a9396686..8f326d35 100644
--- a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSLoadBundleOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSLoadBundleOperation.cs
@@ -11,6 +11,7 @@ namespace YooAsset
None,
CheckExist,
DownloadFile,
+ AbortDownload,
LoadAssetBundle,
CheckResult,
Done,
@@ -63,6 +64,17 @@ namespace YooAsset
}
}
+ if (_steps == ESteps.DownloadFile)
+ {
+ // 中断下载
+ if (AbortDownloadFile)
+ {
+ if (_downloadFileOp != null)
+ _downloadFileOp.AbortOperation();
+ _steps = ESteps.AbortDownload;
+ }
+ }
+
if (_steps == ESteps.DownloadFile)
{
if (_downloadFileOp == null)
@@ -94,6 +106,23 @@ namespace YooAsset
}
}
+ if (_steps == ESteps.AbortDownload)
+ {
+ if (_downloadFileOp != null)
+ {
+ if (IsWaitForAsyncComplete)
+ _downloadFileOp.WaitForAsyncComplete();
+
+ _downloadFileOp.UpdateOperation();
+ if (_downloadFileOp.IsDone == false)
+ return;
+ }
+
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Failed;
+ Error = "Abort download file !";
+ }
+
if (_steps == ESteps.LoadAssetBundle)
{
if (_bundle.Encrypted)
@@ -251,6 +280,7 @@ namespace YooAsset
None,
CheckExist,
DownloadFile,
+ AbortDownload,
LoadCacheRawBundle,
Done,
}
@@ -310,6 +340,17 @@ namespace YooAsset
}
}
+ if (_steps == ESteps.DownloadFile)
+ {
+ // 中断下载
+ if (AbortDownloadFile)
+ {
+ if (_downloadFileOp != null)
+ _downloadFileOp.AbortOperation();
+ _steps = ESteps.AbortDownload;
+ }
+ }
+
if (_steps == ESteps.DownloadFile)
{
if (_downloadFileOp == null)
@@ -341,6 +382,23 @@ namespace YooAsset
}
}
+ if (_steps == ESteps.AbortDownload)
+ {
+ if (_downloadFileOp != null)
+ {
+ if (IsWaitForAsyncComplete)
+ _downloadFileOp.WaitForAsyncComplete();
+
+ _downloadFileOp.UpdateOperation();
+ if (_downloadFileOp.IsDone == false)
+ return;
+ }
+
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Failed;
+ Error = "Abort download file !";
+ }
+
if (_steps == ESteps.LoadCacheRawBundle)
{
string filePath = _fileSystem.GetCacheBundleFileLoadPath(_bundle);
diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/Operation/DEFSLoadBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/Operation/DEFSLoadBundleOperation.cs
index 90560017..65685ce9 100644
--- a/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/Operation/DEFSLoadBundleOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/Operation/DEFSLoadBundleOperation.cs
@@ -8,6 +8,7 @@ namespace YooAsset
None,
CheckExist,
DownloadFile,
+ AbortDownload,
LoadAssetBundle,
CheckResult,
Done,
@@ -48,6 +49,17 @@ namespace YooAsset
}
}
+ if (_steps == ESteps.DownloadFile)
+ {
+ // 中断下载
+ if (AbortDownloadFile)
+ {
+ if (_downloadFileOp != null)
+ _downloadFileOp.AbortOperation();
+ _steps = ESteps.AbortDownload;
+ }
+ }
+
if (_steps == ESteps.DownloadFile)
{
if (_downloadFileOp == null)
@@ -79,6 +91,23 @@ namespace YooAsset
}
}
+ if (_steps == ESteps.AbortDownload)
+ {
+ if (_downloadFileOp != null)
+ {
+ if (IsWaitForAsyncComplete)
+ _downloadFileOp.WaitForAsyncComplete();
+
+ _downloadFileOp.UpdateOperation();
+ if (_downloadFileOp.IsDone == false)
+ return;
+ }
+
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Failed;
+ Error = "Abort download file !";
+ }
+
if (_steps == ESteps.LoadAssetBundle)
{
if (IsWaitForAsyncComplete)
diff --git a/Assets/YooAsset/Runtime/FileSystem/Operation/FSLoadBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Operation/FSLoadBundleOperation.cs
index dcc327d9..19c6d3ce 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Operation/FSLoadBundleOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Operation/FSLoadBundleOperation.cs
@@ -17,6 +17,11 @@ namespace YooAsset
/// 下载大小
///
public long DownloadedBytes { protected set; get; } = 0;
+
+ ///
+ /// 终止下载文件
+ ///
+ public bool AbortDownloadFile = false;
}
internal sealed class FSLoadBundleCompleteOperation : FSLoadBundleOperation
diff --git a/Assets/YooAsset/Runtime/ResourceManager/Operation/Internal/LoadBundleFileOperation.cs b/Assets/YooAsset/Runtime/ResourceManager/Operation/Internal/LoadBundleFileOperation.cs
index 02bafa8e..7519d661 100644
--- a/Assets/YooAsset/Runtime/ResourceManager/Operation/Internal/LoadBundleFileOperation.cs
+++ b/Assets/YooAsset/Runtime/ResourceManager/Operation/Internal/LoadBundleFileOperation.cs
@@ -173,6 +173,13 @@ namespace YooAsset
if (Result != null)
Result.UnloadBundleFile();
+
+ if (IsDone == false)
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Failed;
+ Error = "Bundle loader destroyed !";
+ }
}
///
@@ -256,5 +263,28 @@ namespace YooAsset
_removeList.Clear();
}
}
+
+ ///
+ /// 尝试终止加载器
+ ///
+ public void TryAbortLoader()
+ {
+ if (IsDone == false)
+ {
+ if (_steps == ESteps.CheckConcurrency)
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Failed;
+ Error = "Abort bundle loader !";
+ }
+
+ if (_steps == ESteps.LoadBundleFile)
+ {
+ // 注意:终止下载器
+ if (_loadBundleOp != null)
+ _loadBundleOp.AbortDownloadFile = true;
+ }
+ }
+ }
}
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/ResourceManager/Operation/UnloadAllAssetsOperation.cs b/Assets/YooAsset/Runtime/ResourceManager/Operation/UnloadAllAssetsOperation.cs
index 4a5d1dc4..c5033d92 100644
--- a/Assets/YooAsset/Runtime/ResourceManager/Operation/UnloadAllAssetsOperation.cs
+++ b/Assets/YooAsset/Runtime/ResourceManager/Operation/UnloadAllAssetsOperation.cs
@@ -23,7 +23,7 @@ namespace YooAsset
None,
CheckOptions,
ReleaseAll,
- AbortDownload,
+ TryAbortLoader,
CheckLoading,
DestroyAll,
Done,
@@ -78,15 +78,16 @@ namespace YooAsset
}
}
- _steps = ESteps.AbortDownload;
+ _steps = ESteps.TryAbortLoader;
}
- if (_steps == ESteps.AbortDownload)
+ if (_steps == ESteps.TryAbortLoader)
{
- // 注意:终止所有下载任务
+ // 尝试终止所有加载任务
+ // 注意:正在加载AssetBundle的任务无法终止
foreach (var loader in _resManager.LoaderDic.Values)
{
- loader.AbortOperation();
+ loader.TryAbortLoader();
}
_steps = ESteps.CheckLoading;
}
diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operation/DestroyOperation.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operation/DestroyOperation.cs
index 04e0c7c3..f251a62e 100644
--- a/Assets/YooAsset/Runtime/ResourcePackage/Operation/DestroyOperation.cs
+++ b/Assets/YooAsset/Runtime/ResourcePackage/Operation/DestroyOperation.cs
@@ -13,13 +13,15 @@ namespace YooAsset
}
private readonly ResourcePackage _resourcePackage;
+ private readonly UnloadAllAssetsOptions _options;
private UnloadAllAssetsOperation _unloadAllAssetsOp;
private ESteps _steps = ESteps.None;
- public DestroyOperation(ResourcePackage resourcePackage)
+ public DestroyOperation(ResourcePackage resourcePackage, UnloadAllAssetsOptions options)
{
_resourcePackage = resourcePackage;
+ _options = options;
}
internal override void InternalStart()
@@ -64,7 +66,7 @@ namespace YooAsset
{
if (_unloadAllAssetsOp == null)
{
- _unloadAllAssetsOp = _resourcePackage.UnloadAllAssetsAsync();
+ _unloadAllAssetsOp = _resourcePackage.UnloadAllAssetsAsync(_options);
_unloadAllAssetsOp.StartOperation();
AddChildOperation(_unloadAllAssetsOp);
}
diff --git a/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs b/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs
index 452893c5..3577bc32 100644
--- a/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs
+++ b/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs
@@ -209,7 +209,10 @@ namespace YooAsset
///
public DestroyOperation DestroyAsync()
{
- var operation = new DestroyOperation(this);
+ var options = new UnloadAllAssetsOptions();
+ options.ReleaseAllHandles = true;
+ options.LockLoadOperation = true;
+ var operation = new DestroyOperation(this, options);
OperationSystem.StartOperation(null, operation);
return operation;
}