mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-24 17:50:15 +00:00
fix #661
This commit is contained in:
@@ -11,6 +11,7 @@ namespace YooAsset
|
|||||||
None,
|
None,
|
||||||
CheckExist,
|
CheckExist,
|
||||||
DownloadFile,
|
DownloadFile,
|
||||||
|
AbortDownload,
|
||||||
LoadAssetBundle,
|
LoadAssetBundle,
|
||||||
CheckResult,
|
CheckResult,
|
||||||
Done,
|
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 (_steps == ESteps.DownloadFile)
|
||||||
{
|
{
|
||||||
if (_downloadFileOp == null)
|
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 (_steps == ESteps.LoadAssetBundle)
|
||||||
{
|
{
|
||||||
if (_bundle.Encrypted)
|
if (_bundle.Encrypted)
|
||||||
@@ -251,6 +280,7 @@ namespace YooAsset
|
|||||||
None,
|
None,
|
||||||
CheckExist,
|
CheckExist,
|
||||||
DownloadFile,
|
DownloadFile,
|
||||||
|
AbortDownload,
|
||||||
LoadCacheRawBundle,
|
LoadCacheRawBundle,
|
||||||
Done,
|
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 (_steps == ESteps.DownloadFile)
|
||||||
{
|
{
|
||||||
if (_downloadFileOp == null)
|
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)
|
if (_steps == ESteps.LoadCacheRawBundle)
|
||||||
{
|
{
|
||||||
string filePath = _fileSystem.GetCacheBundleFileLoadPath(_bundle);
|
string filePath = _fileSystem.GetCacheBundleFileLoadPath(_bundle);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ namespace YooAsset
|
|||||||
None,
|
None,
|
||||||
CheckExist,
|
CheckExist,
|
||||||
DownloadFile,
|
DownloadFile,
|
||||||
|
AbortDownload,
|
||||||
LoadAssetBundle,
|
LoadAssetBundle,
|
||||||
CheckResult,
|
CheckResult,
|
||||||
Done,
|
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 (_steps == ESteps.DownloadFile)
|
||||||
{
|
{
|
||||||
if (_downloadFileOp == null)
|
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 (_steps == ESteps.LoadAssetBundle)
|
||||||
{
|
{
|
||||||
if (IsWaitForAsyncComplete)
|
if (IsWaitForAsyncComplete)
|
||||||
|
|||||||
@@ -17,6 +17,11 @@ namespace YooAsset
|
|||||||
/// 下载大小
|
/// 下载大小
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public long DownloadedBytes { protected set; get; } = 0;
|
public long DownloadedBytes { protected set; get; } = 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 终止下载文件
|
||||||
|
/// </summary>
|
||||||
|
public bool AbortDownloadFile = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal sealed class FSLoadBundleCompleteOperation : FSLoadBundleOperation
|
internal sealed class FSLoadBundleCompleteOperation : FSLoadBundleOperation
|
||||||
|
|||||||
@@ -173,6 +173,13 @@ namespace YooAsset
|
|||||||
|
|
||||||
if (Result != null)
|
if (Result != null)
|
||||||
Result.UnloadBundleFile();
|
Result.UnloadBundleFile();
|
||||||
|
|
||||||
|
if (IsDone == false)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = "Bundle loader destroyed !";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -256,5 +263,28 @@ namespace YooAsset
|
|||||||
_removeList.Clear();
|
_removeList.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 尝试终止加载器
|
||||||
|
/// </summary>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,7 @@ namespace YooAsset
|
|||||||
None,
|
None,
|
||||||
CheckOptions,
|
CheckOptions,
|
||||||
ReleaseAll,
|
ReleaseAll,
|
||||||
AbortDownload,
|
TryAbortLoader,
|
||||||
CheckLoading,
|
CheckLoading,
|
||||||
DestroyAll,
|
DestroyAll,
|
||||||
Done,
|
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)
|
foreach (var loader in _resManager.LoaderDic.Values)
|
||||||
{
|
{
|
||||||
loader.AbortOperation();
|
loader.TryAbortLoader();
|
||||||
}
|
}
|
||||||
_steps = ESteps.CheckLoading;
|
_steps = ESteps.CheckLoading;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,13 +13,15 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
|
|
||||||
private readonly ResourcePackage _resourcePackage;
|
private readonly ResourcePackage _resourcePackage;
|
||||||
|
private readonly UnloadAllAssetsOptions _options;
|
||||||
private UnloadAllAssetsOperation _unloadAllAssetsOp;
|
private UnloadAllAssetsOperation _unloadAllAssetsOp;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
|
||||||
public DestroyOperation(ResourcePackage resourcePackage)
|
public DestroyOperation(ResourcePackage resourcePackage, UnloadAllAssetsOptions options)
|
||||||
{
|
{
|
||||||
_resourcePackage = resourcePackage;
|
_resourcePackage = resourcePackage;
|
||||||
|
_options = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override void InternalStart()
|
internal override void InternalStart()
|
||||||
@@ -64,7 +66,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
if (_unloadAllAssetsOp == null)
|
if (_unloadAllAssetsOp == null)
|
||||||
{
|
{
|
||||||
_unloadAllAssetsOp = _resourcePackage.UnloadAllAssetsAsync();
|
_unloadAllAssetsOp = _resourcePackage.UnloadAllAssetsAsync(_options);
|
||||||
_unloadAllAssetsOp.StartOperation();
|
_unloadAllAssetsOp.StartOperation();
|
||||||
AddChildOperation(_unloadAllAssetsOp);
|
AddChildOperation(_unloadAllAssetsOp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -209,7 +209,10 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public DestroyOperation DestroyAsync()
|
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);
|
OperationSystem.StartOperation(null, operation);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user