diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs index 6fba180..a8232eb 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs @@ -286,6 +286,7 @@ namespace YooAsset // 文件解压 if (_unpacker != null) { + _unpacker.WaitForAsyncComplete = true; _unpacker.Update(); if (_unpacker.IsDone() == false) continue; diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/RawBundleFileLoader.cs b/Assets/YooAsset/Runtime/AssetSystem/Loader/RawBundleFileLoader.cs index 103b6eb..1ebf7ff 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Loader/RawBundleFileLoader.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/RawBundleFileLoader.cs @@ -149,6 +149,7 @@ namespace YooAsset // 文件解压 if (_unpacker != null) { + _unpacker.WaitForAsyncComplete = true; _unpacker.Update(); if (_unpacker.IsDone() == false) continue; diff --git a/Assets/YooAsset/Runtime/CacheSystem/Operations/Internal/VerifyTempFileOperation.cs b/Assets/YooAsset/Runtime/CacheSystem/Operations/Internal/VerifyTempFileOperation.cs index 95470b6..55cfdab 100644 --- a/Assets/YooAsset/Runtime/CacheSystem/Operations/Internal/VerifyTempFileOperation.cs +++ b/Assets/YooAsset/Runtime/CacheSystem/Operations/Internal/VerifyTempFileOperation.cs @@ -57,6 +57,25 @@ namespace YooAsset _steps = ESteps.Waiting; } } + + if (_steps == ESteps.Waiting) + { + if (_element.IsDone == false) + return; + + VerifyResult = _element.Result; + if (_element.Result == EVerifyResult.Succeed) + { + _steps = ESteps.Done; + Status = EOperationStatus.Succeed; + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = $"Failed verify file : {_element.TempDataFilePath} ! ErrorCode : {_element.Result}"; + } + } } private bool BeginVerifyFileWithThread(VerifyTempElement element) @@ -67,23 +86,7 @@ namespace YooAsset { VerifyTempElement element = (VerifyTempElement)obj; element.Result = CacheSystem.VerifyingTempFile(element); - DownloadSystem.SyncContext.Post(VerifyCallback, element); - } - private void VerifyCallback(object obj) - { - VerifyTempElement element = (VerifyTempElement)obj; - VerifyResult = element.Result; - if (element.Result == EVerifyResult.Succeed) - { - _steps = ESteps.Done; - Status = EOperationStatus.Succeed; - } - else - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = $"Failed verify file : {element.TempDataFilePath} ! ErrorCode : {element.Result}"; - } + element.IsDone = true; } } @@ -101,7 +104,7 @@ namespace YooAsset private readonly VerifyTempElement _element; private ESteps _steps = ESteps.None; - + public VerifyTempFileWithoutThreadOperation(VerifyTempElement element) { _element = element; @@ -118,6 +121,8 @@ namespace YooAsset if (_steps == ESteps.VerifyFile) { _element.Result = CacheSystem.VerifyingTempFile(_element); + _element.IsDone = true; + VerifyResult = _element.Result; if (_element.Result == EVerifyResult.Succeed) { diff --git a/Assets/YooAsset/Runtime/CacheSystem/VerifyElement.cs b/Assets/YooAsset/Runtime/CacheSystem/VerifyElement.cs index 9384583..9e3841b 100644 --- a/Assets/YooAsset/Runtime/CacheSystem/VerifyElement.cs +++ b/Assets/YooAsset/Runtime/CacheSystem/VerifyElement.cs @@ -49,6 +49,7 @@ namespace YooAsset public string FileCRC { private set; get; } public long FileSize { private set; get; } + public bool IsDone = false; public EVerifyResult Result; public VerifyTempElement(string tempDataFilePath, string fileCRC, long fileSize) diff --git a/Assets/YooAsset/Runtime/DownloadSystem/DownloadSystem.cs b/Assets/YooAsset/Runtime/DownloadSystem/DownloadSystem.cs index 180d7d0..de18ee6 100644 --- a/Assets/YooAsset/Runtime/DownloadSystem/DownloadSystem.cs +++ b/Assets/YooAsset/Runtime/DownloadSystem/DownloadSystem.cs @@ -22,11 +22,6 @@ namespace YooAsset private static readonly Dictionary _downloaderDic = new Dictionary(); private static readonly List _removeList = new List(100); - /// - /// 线程同步 - /// - public static ThreadSyncContext SyncContext { set; get; } - /// /// 自定义下载器的请求委托 /// @@ -53,7 +48,6 @@ namespace YooAsset /// public static void Initialize() { - SyncContext = new ThreadSyncContext(); } /// @@ -61,9 +55,6 @@ namespace YooAsset /// public static void Update() { - if (SyncContext != null) - SyncContext.Update(); - // 更新下载器 _removeList.Clear(); foreach (var valuePair in _downloaderDic) @@ -94,7 +85,6 @@ namespace YooAsset _downloaderDic.Clear(); _removeList.Clear(); - SyncContext = null; RequestDelegate = null; CertificateHandlerInstance = null; BreakpointResumeFileSize = int.MaxValue; diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/DownloaderBase.cs b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/DownloaderBase.cs index 1269d76..7866417 100644 --- a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/DownloaderBase.cs +++ b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/DownloaderBase.cs @@ -34,6 +34,11 @@ namespace YooAsset protected float _downloadProgress = 0f; protected ulong _downloadedBytes = 0; + /// + /// 是否等待异步结束 + /// 警告:只能用于解压APP内部资源 + /// + public bool WaitForAsyncComplete = false; /// /// 下载进度(0f~1f) diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/FileDownloader.cs b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/FileDownloader.cs index 3551619..6071af7 100644 --- a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/FileDownloader.cs +++ b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/FileDownloader.cs @@ -48,6 +48,9 @@ namespace YooAsset // 等待检测结果 if (_steps == ESteps.WaitingCheckTempFile) { + if (WaitForAsyncComplete) + _checkFileOp.Update(); + if (_checkFileOp.IsDone == false) return; @@ -220,6 +223,9 @@ namespace YooAsset // 等待验证完成 if (_steps == ESteps.WaitingVerifyTempFile) { + if (WaitForAsyncComplete) + _verifyFileOp.Update(); + if (_verifyFileOp.IsDone == false) return;