diff --git a/Assets/YooAsset/Runtime/AssetSystem/Handles/OperationHandleBase.cs b/Assets/YooAsset/Runtime/AssetSystem/Handles/OperationHandleBase.cs index 6c8f081..2063543 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Handles/OperationHandleBase.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Handles/OperationHandleBase.cs @@ -23,6 +23,18 @@ namespace YooAsset return _assetInfo; } + /// + /// 获取下载报告 + /// + public DownloadReport GetDownloadReport() + { + if (IsValidWithWarning == false) + { + return DownloadReport.CreateDefaultReport(); + } + return Provider.GetDownloadReport(); + } + /// /// 当前状态 /// @@ -63,7 +75,7 @@ namespace YooAsset { if (IsValidWithWarning == false) return 0; - return Provider.Progress; + return Provider.GetLoadProgress(); } } diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs index 777b2f8..d75f25e 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs @@ -307,5 +307,36 @@ 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 69fba04..59c9e32 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleWebLoader.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleWebLoader.cs @@ -226,5 +226,36 @@ 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 30e4a63..7ad0f6a 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Loader/BundleLoaderBase.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/BundleLoaderBase.cs @@ -18,7 +18,7 @@ namespace YooAsset /// 所属资源系统 /// public AssetSystemImpl Impl { private set; get; } - + /// /// 资源包文件信息 /// @@ -47,7 +47,7 @@ namespace YooAsset private readonly List _providers = new List(100); internal AssetBundle CacheBundle { set; get; } internal string FileLoadPath { set; get; } - + public BundleLoaderBase(AssetSystemImpl impl, BundleInfo bundleInfo) { @@ -82,34 +82,6 @@ namespace YooAsset RefCount--; } - /// - /// 轮询更新 - /// - public abstract void Update(); - - /// - /// 销毁 - /// - public virtual void Destroy(bool forceDestroy) - { - IsDestroyed = true; - - // Check fatal - if (forceDestroy == false) - { - if (RefCount > 0) - throw new Exception($"Bundle file loader ref is not zero : {MainBundleInfo.Bundle.BundleName}"); - if (IsDone() == false) - throw new Exception($"Bundle file loader is not done : {MainBundleInfo.Bundle.BundleName}"); - } - - if (CacheBundle != null) - { - CacheBundle.Unload(true); - CacheBundle = null; - } - } - /// /// 是否完毕(无论成功或失败) /// @@ -159,9 +131,43 @@ namespace YooAsset _providers.Clear(); } + + /// + /// 轮询更新 + /// + public abstract void Update(); + + /// + /// 销毁 + /// + public virtual void Destroy(bool forceDestroy) + { + IsDestroyed = true; + + // Check fatal + if (forceDestroy == false) + { + if (RefCount > 0) + throw new Exception($"Bundle file loader ref is not zero : {MainBundleInfo.Bundle.BundleName}"); + if (IsDone() == false) + throw new Exception($"Bundle file loader is not done : {MainBundleInfo.Bundle.BundleName}"); + } + + if (CacheBundle != null) + { + CacheBundle.Unload(true); + CacheBundle = null; + } + } + /// /// 主线程等待异步操作完毕 /// public abstract void WaitForAsyncComplete(); + + /// + /// 获取下载报告 + /// + public abstract DownloadReport GetDownloadReport(); } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/DependAssetBundleGrouper.cs b/Assets/YooAsset/Runtime/AssetSystem/Loader/DependAssetBundleGrouper.cs index 1de25a3..eb78955 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Loader/DependAssetBundleGrouper.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/DependAssetBundleGrouper.cs @@ -9,12 +9,12 @@ namespace YooAsset /// /// 依赖的资源包加载器列表 /// - private readonly List _dependBundles; + internal readonly List DependBundles; public DependAssetBundleGroup(List dpendBundles) { - _dependBundles = dpendBundles; + DependBundles = dpendBundles; } /// @@ -22,7 +22,7 @@ namespace YooAsset /// public bool IsDone() { - foreach (var loader in _dependBundles) + foreach (var loader in DependBundles) { if (loader.IsDone() == false) return false; @@ -35,7 +35,7 @@ namespace YooAsset /// public bool IsSucceed() { - foreach (var loader in _dependBundles) + foreach (var loader in DependBundles) { if (loader.Status != BundleLoaderBase.EStatus.Succeed) { @@ -50,7 +50,7 @@ namespace YooAsset /// public string GetLastError() { - foreach (var loader in _dependBundles) + foreach (var loader in DependBundles) { if (loader.Status != BundleLoaderBase.EStatus.Succeed) { @@ -65,7 +65,7 @@ namespace YooAsset /// public void WaitForAsyncComplete() { - foreach (var loader in _dependBundles) + foreach (var loader in DependBundles) { if (loader.IsDone() == false) loader.WaitForAsyncComplete(); @@ -77,7 +77,7 @@ namespace YooAsset /// public void Reference() { - foreach (var loader in _dependBundles) + foreach (var loader in DependBundles) { loader.Reference(); } @@ -88,7 +88,7 @@ namespace YooAsset /// public void Release() { - foreach (var loader in _dependBundles) + foreach (var loader in DependBundles) { loader.Release(); } @@ -99,7 +99,7 @@ namespace YooAsset /// internal void GetBundleDebugInfos(List output) { - foreach (var loader in _dependBundles) + foreach (var loader in DependBundles) { var bundleInfo = new DebugBundleInfo(); bundleInfo.BundleName = loader.MainBundleInfo.Bundle.BundleName; diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/RawBundleFileLoader.cs b/Assets/YooAsset/Runtime/AssetSystem/Loader/RawBundleFileLoader.cs index 90be997..c954bc4 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Loader/RawBundleFileLoader.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/RawBundleFileLoader.cs @@ -167,5 +167,36 @@ 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 aa31c9e..3deabc2 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledAssetProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledAssetProvider.cs @@ -7,15 +7,6 @@ namespace YooAsset internal sealed class BundledAssetProvider : BundledProvider { private AssetBundleRequest _cacheRequest; - public override float Progress - { - get - { - if (_cacheRequest == null) - return 0; - return _cacheRequest.progress; - } - } public BundledAssetProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo) { @@ -127,5 +118,11 @@ 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 c83c453..10c0aed 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledProvider.cs @@ -35,6 +35,22 @@ namespace YooAsset } } + /// + /// 获取下载报告 + /// + public override DownloadReport GetDownloadReport() + { + DownloadReport result = OwnerBundle.GetDownloadReport(); + foreach (var bundleLoader in DependBundleGroup.DependBundles) + { + var report = bundleLoader.GetDownloadReport(); + result.TotalSize += report.TotalSize; + result.DownloadedBytes += report.DownloadedBytes; + } + result.Progress = result.DownloadedBytes / result.TotalSize; + return result; + } + /// /// 获取资源包的调试信息列表 /// diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledRawFileProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledRawFileProvider.cs index 4c6401e..80a2a9f 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledRawFileProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledRawFileProvider.cs @@ -3,17 +3,6 @@ namespace YooAsset { internal class BundledRawFileProvider : BundledProvider { - public override float Progress - { - get - { - if (IsDone) - return 1f; - else - return 0; - } - } - public BundledRawFileProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo) { } diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSceneProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSceneProvider.cs index 79e36eb..34c4d27 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSceneProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSceneProvider.cs @@ -13,15 +13,6 @@ namespace YooAsset private readonly bool _activateOnLoad; private readonly int _priority; private AsyncOperation _asyncOp; - public override float Progress - { - get - { - if (_asyncOp == null) - return 0; - return _asyncOp.progress; - } - } public BundledSceneProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool activateOnLoad, int priority) : base(impl, providerGUID, assetInfo) { @@ -108,5 +99,11 @@ 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 8810ac7..d34a5cb 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSubAssetsProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSubAssetsProvider.cs @@ -7,15 +7,6 @@ namespace YooAsset internal sealed class BundledSubAssetsProvider : BundledProvider { private AssetBundleRequest _cacheRequest; - public override float Progress - { - get - { - if (_cacheRequest == null) - return 0; - return _cacheRequest.progress; - } - } public BundledSubAssetsProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo) { @@ -116,5 +107,11 @@ 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/CompletedProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/CompletedProvider.cs index f9973e1..c87ad37 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/CompletedProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/CompletedProvider.cs @@ -3,17 +3,6 @@ namespace YooAsset { internal sealed class CompletedProvider : ProviderBase { - public override float Progress - { - get - { - if (IsDone) - return 1f; - else - return 0; - } - } - public CompletedProvider(AssetInfo assetInfo) : base(null, string.Empty, assetInfo) { } diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseAssetProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseAssetProvider.cs index 9b2045d..8363518 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseAssetProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseAssetProvider.cs @@ -6,17 +6,6 @@ namespace YooAsset { internal sealed class DatabaseAssetProvider : ProviderBase { - public override float Progress - { - get - { - if (IsDone) - return 1f; - else - return 0; - } - } - public DatabaseAssetProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo) { } diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseRawFileProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseRawFileProvider.cs index 380c23e..3e609e8 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseRawFileProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseRawFileProvider.cs @@ -3,17 +3,6 @@ namespace YooAsset { internal class DatabaseRawFileProvider : ProviderBase { - public override float Progress - { - get - { - if (IsDone) - return 1f; - else - return 0; - } - } - public DatabaseRawFileProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo) { } diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSceneProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSceneProvider.cs index c41a998..6b4dc12 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSceneProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSceneProvider.cs @@ -9,15 +9,6 @@ namespace YooAsset private readonly bool _activateOnLoad; private readonly int _priority; private AsyncOperation _asyncOp; - public override float Progress - { - get - { - if (_asyncOp == null) - return 0; - return _asyncOp.progress; - } - } public DatabaseSceneProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool activateOnLoad, int priority) : base(impl, providerGUID, assetInfo) { @@ -77,5 +68,11 @@ 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/DatabaseSubAssetsProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSubAssetsProvider.cs index c3069d9..d6d1b94 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSubAssetsProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSubAssetsProvider.cs @@ -6,17 +6,6 @@ namespace YooAsset { internal sealed class DatabaseSubAssetsProvider : ProviderBase { - public override float Progress - { - get - { - if (IsDone) - return 1f; - else - return 0; - } - } - public DatabaseSubAssetsProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo) { } diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/ProviderBase.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/ProviderBase.cs index 598a508..39b9bb8 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/ProviderBase.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/ProviderBase.cs @@ -84,17 +84,6 @@ namespace YooAsset } } - /// - /// 加载进度 - /// - public virtual float Progress - { - get - { - return 0; - } - } - protected bool IsWaitForAsyncComplete { private set; get; } = false; private readonly List _handles = new List(); @@ -120,6 +109,25 @@ namespace YooAsset IsDestroyed = true; } + /// + /// 获取加载进度 + /// + public virtual float GetLoadProgress() + { + if (IsDone) + return 1f; + else + return 0; + } + + /// + /// 获取下载进度 + /// + public virtual DownloadReport GetDownloadReport() + { + return DownloadReport.CreateDefaultReport(); + } + /// /// 是否可以销毁 /// diff --git a/Assets/YooAsset/Runtime/DownloadSystem/DownloadReport.cs b/Assets/YooAsset/Runtime/DownloadSystem/DownloadReport.cs new file mode 100644 index 0000000..31b81bb --- /dev/null +++ b/Assets/YooAsset/Runtime/DownloadSystem/DownloadReport.cs @@ -0,0 +1,30 @@ + +namespace YooAsset +{ + public struct DownloadReport + { + /// + /// 下载进度(0f~1f) + /// + public float Progress; + + /// + /// 需要下载的总字节数 + /// + public long TotalSize; + + /// + /// 已经下载的字节数 + /// + public long DownloadedBytes; + + public static DownloadReport CreateDefaultReport() + { + DownloadReport report = new DownloadReport(); + report.Progress = 1f; + report.TotalSize = 0; + report.DownloadedBytes = 0; + return report; + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/DownloadSystem/DownloadReport.cs.meta b/Assets/YooAsset/Runtime/DownloadSystem/DownloadReport.cs.meta new file mode 100644 index 0000000..43818f2 --- /dev/null +++ b/Assets/YooAsset/Runtime/DownloadSystem/DownloadReport.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d40b8341fcd4ad2478eb1a890ebf0476 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/DownloaderBase.cs b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/DownloaderBase.cs index 22e6d9e..bcd04dc 100644 --- a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/DownloaderBase.cs +++ b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/DownloaderBase.cs @@ -30,7 +30,7 @@ namespace YooAsset /// - /// 下载进度 + /// 下载进度(0f~1f) /// public float DownloadProgress {