diff --git a/Assets/YooAsset/Runtime/AssetSystem/Handles/OperationHandleBase.cs b/Assets/YooAsset/Runtime/AssetSystem/Handles/OperationHandleBase.cs index 2063543..2dde697 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Handles/OperationHandleBase.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Handles/OperationHandleBase.cs @@ -75,7 +75,7 @@ namespace YooAsset { if (IsValidWithWarning == false) return 0; - return Provider.GetLoadProgress(); + return Provider.Progress; } } diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs index d75f25e..1f0a8df 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs @@ -89,6 +89,8 @@ namespace YooAsset // 2. 检测服务器下载结果 if (_steps == ESteps.CheckDownload) { + DownloadProgress = _downloader.DownloadProgress; + DownloadedBytes = _downloader.DownloadedBytes; if (_downloader.IsDone() == false) return; @@ -116,6 +118,8 @@ namespace YooAsset // 4.检测内置文件解压结果 if (_steps == ESteps.CheckUnpack) { + DownloadProgress = _unpacker.DownloadProgress; + DownloadedBytes = _unpacker.DownloadedBytes; if (_unpacker.IsDone() == false) return; @@ -146,6 +150,10 @@ namespace YooAsset } #endif + // 设置下载进度 + DownloadProgress = 1f; + DownloadedBytes = (ulong)MainBundleInfo.Bundle.FileSize; + // Load assetBundle file var loadMethod = (EBundleLoadMethod)MainBundleInfo.Bundle.LoadMethod; if (loadMethod == EBundleLoadMethod.Normal) @@ -307,36 +315,5 @@ namespace YooAsset break; } } - - /// - /// 获取下载报告 - /// - public override DownloadReport GetDownloadReport() - { - if (_downloader != null) - { - DownloadReport report = new DownloadReport(); - report.Progress = _downloader.DownloadProgress; - report.TotalSize = MainBundleInfo.Bundle.FileSize; - report.DownloadedBytes = (long)_downloader.DownloadedBytes; - return report; - } - else if(_unpacker != null) - { - DownloadReport report = new DownloadReport(); - report.Progress = _unpacker.DownloadProgress; - report.TotalSize = MainBundleInfo.Bundle.FileSize; - report.DownloadedBytes = (long)_unpacker.DownloadedBytes; - return report; - } - else - { - DownloadReport report = new DownloadReport(); - report.Progress = 1f; - report.TotalSize = MainBundleInfo.Bundle.FileSize; - report.DownloadedBytes = MainBundleInfo.Bundle.FileSize; - return report; - } - } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleWebLoader.cs b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleWebLoader.cs index 59c9e32..5a68de7 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleWebLoader.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleWebLoader.cs @@ -76,6 +76,8 @@ namespace YooAsset // 2. 检测服务器下载结果 if (_steps == ESteps.CheckDownload) { + DownloadProgress = _downloader.DownloadProgress; + DownloadedBytes = _downloader.DownloadedBytes; if (_downloader.IsDone() == false) return; @@ -106,6 +108,10 @@ namespace YooAsset } #endif + // 设置下载进度 + DownloadProgress = 1f; + DownloadedBytes = (ulong)MainBundleInfo.Bundle.FileSize; + // Load assetBundle file var loadMethod = (EBundleLoadMethod)MainBundleInfo.Bundle.LoadMethod; if (loadMethod == EBundleLoadMethod.Normal) @@ -171,6 +177,8 @@ namespace YooAsset // 6. 检测AssetBundle加载结果 if (_steps == ESteps.CheckLoadWebFile) { + DownloadProgress = _webRequest.downloadProgress; + DownloadedBytes = _webRequest.downloadedBytes; if (_webRequest.isDone == false) return; @@ -226,36 +234,5 @@ namespace YooAsset YooLogger.Error($"WebGL platform not support {nameof(WaitForAsyncComplete)} ! Use the async load method instead of the sync load method !"); } } - - /// - /// 获取下载报告 - /// - public override DownloadReport GetDownloadReport() - { - if (_downloader != null) - { - DownloadReport report = new DownloadReport(); - report.Progress = _downloader.DownloadProgress; - report.TotalSize = MainBundleInfo.Bundle.FileSize; - report.DownloadedBytes = (long)_downloader.DownloadedBytes; - return report; - } - else if (_webRequest != null) - { - DownloadReport report = new DownloadReport(); - report.Progress = _webRequest.downloadProgress; - report.TotalSize = MainBundleInfo.Bundle.FileSize; - report.DownloadedBytes = (long)_webRequest.downloadedBytes; - return report; - } - else - { - DownloadReport report = new DownloadReport(); - report.Progress = 1f; - report.TotalSize = MainBundleInfo.Bundle.FileSize; - report.DownloadedBytes = MainBundleInfo.Bundle.FileSize; - return report; - } - } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/BundleLoaderBase.cs b/Assets/YooAsset/Runtime/AssetSystem/Loader/BundleLoaderBase.cs index 7ad0f6a..dc9ef22 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Loader/BundleLoaderBase.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/BundleLoaderBase.cs @@ -47,6 +47,8 @@ namespace YooAsset private readonly List _providers = new List(100); internal AssetBundle CacheBundle { set; get; } internal string FileLoadPath { set; get; } + internal float DownloadProgress { set; get; } + internal ulong DownloadedBytes { set; get; } public BundleLoaderBase(AssetSystemImpl impl, BundleInfo bundleInfo) @@ -164,10 +166,5 @@ namespace YooAsset /// 主线程等待异步操作完毕 /// public abstract void WaitForAsyncComplete(); - - /// - /// 获取下载报告 - /// - public abstract DownloadReport GetDownloadReport(); } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/RawBundleFileLoader.cs b/Assets/YooAsset/Runtime/AssetSystem/Loader/RawBundleFileLoader.cs index c954bc4..7b4d393 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Loader/RawBundleFileLoader.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/RawBundleFileLoader.cs @@ -72,6 +72,8 @@ namespace YooAsset // 2. 检测下载结果 if (_steps == ESteps.CheckDownload) { + DownloadProgress = _downloader.DownloadProgress; + DownloadedBytes = _downloader.DownloadedBytes; if (_downloader.IsDone() == false) return; @@ -99,6 +101,8 @@ namespace YooAsset // 4. 检测解压结果 if (_steps == ESteps.CheckUnpack) { + DownloadProgress = _unpacker.DownloadProgress; + DownloadedBytes = _unpacker.DownloadedBytes; if (_unpacker.IsDone() == false) return; @@ -117,6 +121,10 @@ namespace YooAsset // 5. 检测结果 if (_steps == ESteps.CheckFile) { + // 设置下载进度 + DownloadProgress = 1f; + DownloadedBytes = (ulong)MainBundleInfo.Bundle.FileSize; + _steps = ESteps.Done; if (File.Exists(FileLoadPath)) { @@ -167,36 +175,5 @@ namespace YooAsset break; } } - - /// - /// 获取下载报告 - /// - public override DownloadReport GetDownloadReport() - { - if (_downloader != null) - { - DownloadReport report = new DownloadReport(); - report.Progress = _downloader.DownloadProgress; - report.TotalSize = MainBundleInfo.Bundle.FileSize; - report.DownloadedBytes = (long)_downloader.DownloadedBytes; - return report; - } - else if (_unpacker != null) - { - DownloadReport report = new DownloadReport(); - report.Progress = _unpacker.DownloadProgress; - report.TotalSize = MainBundleInfo.Bundle.FileSize; - report.DownloadedBytes = (long)_unpacker.DownloadedBytes; - return report; - } - else - { - DownloadReport report = new DownloadReport(); - report.Progress = 1f; - report.TotalSize = MainBundleInfo.Bundle.FileSize; - report.DownloadedBytes = MainBundleInfo.Bundle.FileSize; - return report; - } - } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledAssetProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledAssetProvider.cs index 3deabc2..c009c62 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledAssetProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledAssetProvider.cs @@ -90,6 +90,7 @@ namespace YooAsset // 3. 检测加载结果 if (Status == EStatus.Checking) { + Progress = _cacheRequest.progress; if (_cacheRequest != null) { if (IsWaitForAsyncComplete) @@ -118,11 +119,5 @@ namespace YooAsset InvokeCompletion(); } } - public override float GetLoadProgress() - { - if (_cacheRequest == null) - return 0; - return _cacheRequest.progress; - } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledProvider.cs index 10c0aed..340173a 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledProvider.cs @@ -40,12 +40,13 @@ namespace YooAsset /// public override DownloadReport GetDownloadReport() { - DownloadReport result = OwnerBundle.GetDownloadReport(); - foreach (var bundleLoader in DependBundleGroup.DependBundles) + DownloadReport result = new DownloadReport(); + result.TotalSize = (ulong)OwnerBundle.MainBundleInfo.Bundle.FileSize; + result.DownloadedBytes = OwnerBundle.DownloadedBytes; + foreach (var dependBundle in DependBundleGroup.DependBundles) { - var report = bundleLoader.GetDownloadReport(); - result.TotalSize += report.TotalSize; - result.DownloadedBytes += report.DownloadedBytes; + result.TotalSize += (ulong)dependBundle.MainBundleInfo.Bundle.FileSize; + result.DownloadedBytes += dependBundle.DownloadedBytes; } result.Progress = result.DownloadedBytes / result.TotalSize; return result; diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSceneProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSceneProvider.cs index 34c4d27..6a9bd22 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSceneProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSceneProvider.cs @@ -84,6 +84,7 @@ namespace YooAsset // 3. 检测加载结果 if (Status == EStatus.Checking) { + Progress = _asyncOp.progress; if (_asyncOp.isDone) { if (SceneObject.IsValid() && _activateOnLoad) @@ -99,11 +100,5 @@ namespace YooAsset } } } - public override float GetLoadProgress() - { - if (_asyncOp == null) - return 0; - return _asyncOp.progress; - } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSubAssetsProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSubAssetsProvider.cs index d34a5cb..b10807f 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSubAssetsProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSubAssetsProvider.cs @@ -79,6 +79,7 @@ namespace YooAsset // 3. 检测加载结果 if (Status == EStatus.Checking) { + Progress = _cacheRequest.progress; if (_cacheRequest != null) { if (IsWaitForAsyncComplete) @@ -107,11 +108,5 @@ namespace YooAsset InvokeCompletion(); } } - public override float GetLoadProgress() - { - if (_cacheRequest == null) - return 0; - return _cacheRequest.progress; - } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSceneProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSceneProvider.cs index 6b4dc12..962d64f 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSceneProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSceneProvider.cs @@ -52,6 +52,7 @@ namespace YooAsset // 2. 检测加载结果 if (Status == EStatus.Checking) { + Progress = _asyncOp.progress; if (_asyncOp.isDone) { if (SceneObject.IsValid() && _activateOnLoad) @@ -68,11 +69,5 @@ namespace YooAsset } #endif } - public override float GetLoadProgress() - { - if (_asyncOp == null) - return 0; - return _asyncOp.progress; - } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/ProviderBase.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/ProviderBase.cs index 39b9bb8..806314c 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/ProviderBase.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/ProviderBase.cs @@ -63,6 +63,11 @@ namespace YooAsset /// public string LastError { protected set; get; } = string.Empty; + /// + /// 加载进度 + /// + public float Progress { protected set; get; } = 0f; + /// /// 引用计数 /// @@ -109,17 +114,6 @@ namespace YooAsset IsDestroyed = true; } - /// - /// 获取加载进度 - /// - public virtual float GetLoadProgress() - { - if (IsDone) - return 1f; - else - return 0; - } - /// /// 获取下载进度 /// @@ -227,6 +221,9 @@ namespace YooAsset private TaskCompletionSource _taskCompletionSource; protected void InvokeCompletion() { + // 进度百分百完成 + Progress = 1f; + // 注意:创建临时列表是为了防止外部逻辑在回调函数内创建或者释放资源句柄。 List tempers = new List(_handles); foreach (var hande in tempers) diff --git a/Assets/YooAsset/Runtime/DownloadSystem/DownloadReport.cs b/Assets/YooAsset/Runtime/DownloadSystem/DownloadReport.cs index 31b81bb..b1c8c6a 100644 --- a/Assets/YooAsset/Runtime/DownloadSystem/DownloadReport.cs +++ b/Assets/YooAsset/Runtime/DownloadSystem/DownloadReport.cs @@ -11,17 +11,17 @@ namespace YooAsset /// /// 需要下载的总字节数 /// - public long TotalSize; + public ulong TotalSize; /// /// 已经下载的字节数 /// - public long DownloadedBytes; + public ulong DownloadedBytes; public static DownloadReport CreateDefaultReport() { DownloadReport report = new DownloadReport(); - report.Progress = 1f; + report.Progress = 0f; report.TotalSize = 0; report.DownloadedBytes = 0; return report;