update asset sytem

资源句柄类增加GetDownloadReport()方法。
pull/62/head
hevinci 2022-12-05 14:36:26 +08:00
parent 5197d42807
commit ac88fd5cf6
20 changed files with 252 additions and 143 deletions

View File

@ -23,6 +23,18 @@ namespace YooAsset
return _assetInfo; return _assetInfo;
} }
/// <summary>
/// 获取下载报告
/// </summary>
public DownloadReport GetDownloadReport()
{
if (IsValidWithWarning == false)
{
return DownloadReport.CreateDefaultReport();
}
return Provider.GetDownloadReport();
}
/// <summary> /// <summary>
/// 当前状态 /// 当前状态
/// </summary> /// </summary>
@ -63,7 +75,7 @@ namespace YooAsset
{ {
if (IsValidWithWarning == false) if (IsValidWithWarning == false)
return 0; return 0;
return Provider.Progress; return Provider.GetLoadProgress();
} }
} }

View File

@ -307,5 +307,36 @@ namespace YooAsset
break; break;
} }
} }
/// <summary>
/// 获取下载报告
/// </summary>
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;
}
}
} }
} }

View File

@ -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 !"); YooLogger.Error($"WebGL platform not support {nameof(WaitForAsyncComplete)} ! Use the async load method instead of the sync load method !");
} }
} }
/// <summary>
/// 获取下载报告
/// </summary>
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;
}
}
} }
} }

View File

@ -82,34 +82,6 @@ namespace YooAsset
RefCount--; RefCount--;
} }
/// <summary>
/// 轮询更新
/// </summary>
public abstract void Update();
/// <summary>
/// 销毁
/// </summary>
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;
}
}
/// <summary> /// <summary>
/// 是否完毕(无论成功或失败) /// 是否完毕(无论成功或失败)
/// </summary> /// </summary>
@ -159,9 +131,43 @@ namespace YooAsset
_providers.Clear(); _providers.Clear();
} }
/// <summary>
/// 轮询更新
/// </summary>
public abstract void Update();
/// <summary>
/// 销毁
/// </summary>
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;
}
}
/// <summary> /// <summary>
/// 主线程等待异步操作完毕 /// 主线程等待异步操作完毕
/// </summary> /// </summary>
public abstract void WaitForAsyncComplete(); public abstract void WaitForAsyncComplete();
/// <summary>
/// 获取下载报告
/// </summary>
public abstract DownloadReport GetDownloadReport();
} }
} }

View File

@ -9,12 +9,12 @@ namespace YooAsset
/// <summary> /// <summary>
/// 依赖的资源包加载器列表 /// 依赖的资源包加载器列表
/// </summary> /// </summary>
private readonly List<BundleLoaderBase> _dependBundles; internal readonly List<BundleLoaderBase> DependBundles;
public DependAssetBundleGroup(List<BundleLoaderBase> dpendBundles) public DependAssetBundleGroup(List<BundleLoaderBase> dpendBundles)
{ {
_dependBundles = dpendBundles; DependBundles = dpendBundles;
} }
/// <summary> /// <summary>
@ -22,7 +22,7 @@ namespace YooAsset
/// </summary> /// </summary>
public bool IsDone() public bool IsDone()
{ {
foreach (var loader in _dependBundles) foreach (var loader in DependBundles)
{ {
if (loader.IsDone() == false) if (loader.IsDone() == false)
return false; return false;
@ -35,7 +35,7 @@ namespace YooAsset
/// </summary> /// </summary>
public bool IsSucceed() public bool IsSucceed()
{ {
foreach (var loader in _dependBundles) foreach (var loader in DependBundles)
{ {
if (loader.Status != BundleLoaderBase.EStatus.Succeed) if (loader.Status != BundleLoaderBase.EStatus.Succeed)
{ {
@ -50,7 +50,7 @@ namespace YooAsset
/// </summary> /// </summary>
public string GetLastError() public string GetLastError()
{ {
foreach (var loader in _dependBundles) foreach (var loader in DependBundles)
{ {
if (loader.Status != BundleLoaderBase.EStatus.Succeed) if (loader.Status != BundleLoaderBase.EStatus.Succeed)
{ {
@ -65,7 +65,7 @@ namespace YooAsset
/// </summary> /// </summary>
public void WaitForAsyncComplete() public void WaitForAsyncComplete()
{ {
foreach (var loader in _dependBundles) foreach (var loader in DependBundles)
{ {
if (loader.IsDone() == false) if (loader.IsDone() == false)
loader.WaitForAsyncComplete(); loader.WaitForAsyncComplete();
@ -77,7 +77,7 @@ namespace YooAsset
/// </summary> /// </summary>
public void Reference() public void Reference()
{ {
foreach (var loader in _dependBundles) foreach (var loader in DependBundles)
{ {
loader.Reference(); loader.Reference();
} }
@ -88,7 +88,7 @@ namespace YooAsset
/// </summary> /// </summary>
public void Release() public void Release()
{ {
foreach (var loader in _dependBundles) foreach (var loader in DependBundles)
{ {
loader.Release(); loader.Release();
} }
@ -99,7 +99,7 @@ namespace YooAsset
/// </summary> /// </summary>
internal void GetBundleDebugInfos(List<DebugBundleInfo> output) internal void GetBundleDebugInfos(List<DebugBundleInfo> output)
{ {
foreach (var loader in _dependBundles) foreach (var loader in DependBundles)
{ {
var bundleInfo = new DebugBundleInfo(); var bundleInfo = new DebugBundleInfo();
bundleInfo.BundleName = loader.MainBundleInfo.Bundle.BundleName; bundleInfo.BundleName = loader.MainBundleInfo.Bundle.BundleName;

View File

@ -167,5 +167,36 @@ namespace YooAsset
break; break;
} }
} }
/// <summary>
/// 获取下载报告
/// </summary>
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;
}
}
} }
} }

View File

@ -7,15 +7,6 @@ namespace YooAsset
internal sealed class BundledAssetProvider : BundledProvider internal sealed class BundledAssetProvider : BundledProvider
{ {
private AssetBundleRequest _cacheRequest; 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) public BundledAssetProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
{ {
@ -127,5 +118,11 @@ namespace YooAsset
InvokeCompletion(); InvokeCompletion();
} }
} }
public override float GetLoadProgress()
{
if (_cacheRequest == null)
return 0;
return _cacheRequest.progress;
}
} }
} }

View File

@ -35,6 +35,22 @@ namespace YooAsset
} }
} }
/// <summary>
/// 获取下载报告
/// </summary>
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;
}
/// <summary> /// <summary>
/// 获取资源包的调试信息列表 /// 获取资源包的调试信息列表
/// </summary> /// </summary>

View File

@ -3,17 +3,6 @@ namespace YooAsset
{ {
internal class BundledRawFileProvider : BundledProvider 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) public BundledRawFileProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
{ {
} }

View File

@ -13,15 +13,6 @@ namespace YooAsset
private readonly bool _activateOnLoad; private readonly bool _activateOnLoad;
private readonly int _priority; private readonly int _priority;
private AsyncOperation _asyncOp; 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) 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;
}
} }
} }

View File

@ -7,15 +7,6 @@ namespace YooAsset
internal sealed class BundledSubAssetsProvider : BundledProvider internal sealed class BundledSubAssetsProvider : BundledProvider
{ {
private AssetBundleRequest _cacheRequest; 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) public BundledSubAssetsProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
{ {
@ -116,5 +107,11 @@ namespace YooAsset
InvokeCompletion(); InvokeCompletion();
} }
} }
public override float GetLoadProgress()
{
if (_cacheRequest == null)
return 0;
return _cacheRequest.progress;
}
} }
} }

View File

@ -3,17 +3,6 @@ namespace YooAsset
{ {
internal sealed class CompletedProvider : ProviderBase 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) public CompletedProvider(AssetInfo assetInfo) : base(null, string.Empty, assetInfo)
{ {
} }

View File

@ -6,17 +6,6 @@ namespace YooAsset
{ {
internal sealed class DatabaseAssetProvider : ProviderBase 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) public DatabaseAssetProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
{ {
} }

View File

@ -3,17 +3,6 @@ namespace YooAsset
{ {
internal class DatabaseRawFileProvider : ProviderBase 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) public DatabaseRawFileProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
{ {
} }

View File

@ -9,15 +9,6 @@ namespace YooAsset
private readonly bool _activateOnLoad; private readonly bool _activateOnLoad;
private readonly int _priority; private readonly int _priority;
private AsyncOperation _asyncOp; 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) 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 #endif
} }
public override float GetLoadProgress()
{
if (_asyncOp == null)
return 0;
return _asyncOp.progress;
}
} }
} }

View File

@ -6,17 +6,6 @@ namespace YooAsset
{ {
internal sealed class DatabaseSubAssetsProvider : ProviderBase 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) public DatabaseSubAssetsProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
{ {
} }

View File

@ -84,17 +84,6 @@ namespace YooAsset
} }
} }
/// <summary>
/// 加载进度
/// </summary>
public virtual float Progress
{
get
{
return 0;
}
}
protected bool IsWaitForAsyncComplete { private set; get; } = false; protected bool IsWaitForAsyncComplete { private set; get; } = false;
private readonly List<OperationHandleBase> _handles = new List<OperationHandleBase>(); private readonly List<OperationHandleBase> _handles = new List<OperationHandleBase>();
@ -120,6 +109,25 @@ namespace YooAsset
IsDestroyed = true; IsDestroyed = true;
} }
/// <summary>
/// 获取加载进度
/// </summary>
public virtual float GetLoadProgress()
{
if (IsDone)
return 1f;
else
return 0;
}
/// <summary>
/// 获取下载进度
/// </summary>
public virtual DownloadReport GetDownloadReport()
{
return DownloadReport.CreateDefaultReport();
}
/// <summary> /// <summary>
/// 是否可以销毁 /// 是否可以销毁
/// </summary> /// </summary>

View File

@ -0,0 +1,30 @@

namespace YooAsset
{
public struct DownloadReport
{
/// <summary>
/// 下载进度0f~1f
/// </summary>
public float Progress;
/// <summary>
/// 需要下载的总字节数
/// </summary>
public long TotalSize;
/// <summary>
/// 已经下载的字节数
/// </summary>
public long DownloadedBytes;
public static DownloadReport CreateDefaultReport()
{
DownloadReport report = new DownloadReport();
report.Progress = 1f;
report.TotalSize = 0;
report.DownloadedBytes = 0;
return report;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d40b8341fcd4ad2478eb1a890ebf0476
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -30,7 +30,7 @@ namespace YooAsset
/// <summary> /// <summary>
/// 下载进度 /// 下载进度0f~1f
/// </summary> /// </summary>
public float DownloadProgress public float DownloadProgress
{ {