update asset system

pull/62/head
hevinci 2022-12-05 16:29:45 +08:00
parent ac88fd5cf6
commit 824d1c1501
12 changed files with 48 additions and 142 deletions

View File

@ -75,7 +75,7 @@ namespace YooAsset
{ {
if (IsValidWithWarning == false) if (IsValidWithWarning == false)
return 0; return 0;
return Provider.GetLoadProgress(); return Provider.Progress;
} }
} }

View File

@ -89,6 +89,8 @@ namespace YooAsset
// 2. 检测服务器下载结果 // 2. 检测服务器下载结果
if (_steps == ESteps.CheckDownload) if (_steps == ESteps.CheckDownload)
{ {
DownloadProgress = _downloader.DownloadProgress;
DownloadedBytes = _downloader.DownloadedBytes;
if (_downloader.IsDone() == false) if (_downloader.IsDone() == false)
return; return;
@ -116,6 +118,8 @@ namespace YooAsset
// 4.检测内置文件解压结果 // 4.检测内置文件解压结果
if (_steps == ESteps.CheckUnpack) if (_steps == ESteps.CheckUnpack)
{ {
DownloadProgress = _unpacker.DownloadProgress;
DownloadedBytes = _unpacker.DownloadedBytes;
if (_unpacker.IsDone() == false) if (_unpacker.IsDone() == false)
return; return;
@ -146,6 +150,10 @@ namespace YooAsset
} }
#endif #endif
// 设置下载进度
DownloadProgress = 1f;
DownloadedBytes = (ulong)MainBundleInfo.Bundle.FileSize;
// Load assetBundle file // Load assetBundle file
var loadMethod = (EBundleLoadMethod)MainBundleInfo.Bundle.LoadMethod; var loadMethod = (EBundleLoadMethod)MainBundleInfo.Bundle.LoadMethod;
if (loadMethod == EBundleLoadMethod.Normal) if (loadMethod == EBundleLoadMethod.Normal)
@ -307,36 +315,5 @@ 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

@ -76,6 +76,8 @@ namespace YooAsset
// 2. 检测服务器下载结果 // 2. 检测服务器下载结果
if (_steps == ESteps.CheckDownload) if (_steps == ESteps.CheckDownload)
{ {
DownloadProgress = _downloader.DownloadProgress;
DownloadedBytes = _downloader.DownloadedBytes;
if (_downloader.IsDone() == false) if (_downloader.IsDone() == false)
return; return;
@ -106,6 +108,10 @@ namespace YooAsset
} }
#endif #endif
// 设置下载进度
DownloadProgress = 1f;
DownloadedBytes = (ulong)MainBundleInfo.Bundle.FileSize;
// Load assetBundle file // Load assetBundle file
var loadMethod = (EBundleLoadMethod)MainBundleInfo.Bundle.LoadMethod; var loadMethod = (EBundleLoadMethod)MainBundleInfo.Bundle.LoadMethod;
if (loadMethod == EBundleLoadMethod.Normal) if (loadMethod == EBundleLoadMethod.Normal)
@ -171,6 +177,8 @@ namespace YooAsset
// 6. 检测AssetBundle加载结果 // 6. 检测AssetBundle加载结果
if (_steps == ESteps.CheckLoadWebFile) if (_steps == ESteps.CheckLoadWebFile)
{ {
DownloadProgress = _webRequest.downloadProgress;
DownloadedBytes = _webRequest.downloadedBytes;
if (_webRequest.isDone == false) if (_webRequest.isDone == false)
return; 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 !"); 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

@ -47,6 +47,8 @@ namespace YooAsset
private readonly List<ProviderBase> _providers = new List<ProviderBase>(100); private readonly List<ProviderBase> _providers = new List<ProviderBase>(100);
internal AssetBundle CacheBundle { set; get; } internal AssetBundle CacheBundle { set; get; }
internal string FileLoadPath { set; get; } internal string FileLoadPath { set; get; }
internal float DownloadProgress { set; get; }
internal ulong DownloadedBytes { set; get; }
public BundleLoaderBase(AssetSystemImpl impl, BundleInfo bundleInfo) public BundleLoaderBase(AssetSystemImpl impl, BundleInfo bundleInfo)
@ -164,10 +166,5 @@ namespace YooAsset
/// 主线程等待异步操作完毕 /// 主线程等待异步操作完毕
/// </summary> /// </summary>
public abstract void WaitForAsyncComplete(); public abstract void WaitForAsyncComplete();
/// <summary>
/// 获取下载报告
/// </summary>
public abstract DownloadReport GetDownloadReport();
} }
} }

View File

@ -72,6 +72,8 @@ namespace YooAsset
// 2. 检测下载结果 // 2. 检测下载结果
if (_steps == ESteps.CheckDownload) if (_steps == ESteps.CheckDownload)
{ {
DownloadProgress = _downloader.DownloadProgress;
DownloadedBytes = _downloader.DownloadedBytes;
if (_downloader.IsDone() == false) if (_downloader.IsDone() == false)
return; return;
@ -99,6 +101,8 @@ namespace YooAsset
// 4. 检测解压结果 // 4. 检测解压结果
if (_steps == ESteps.CheckUnpack) if (_steps == ESteps.CheckUnpack)
{ {
DownloadProgress = _unpacker.DownloadProgress;
DownloadedBytes = _unpacker.DownloadedBytes;
if (_unpacker.IsDone() == false) if (_unpacker.IsDone() == false)
return; return;
@ -117,6 +121,10 @@ namespace YooAsset
// 5. 检测结果 // 5. 检测结果
if (_steps == ESteps.CheckFile) if (_steps == ESteps.CheckFile)
{ {
// 设置下载进度
DownloadProgress = 1f;
DownloadedBytes = (ulong)MainBundleInfo.Bundle.FileSize;
_steps = ESteps.Done; _steps = ESteps.Done;
if (File.Exists(FileLoadPath)) if (File.Exists(FileLoadPath))
{ {
@ -167,36 +175,5 @@ 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

@ -90,6 +90,7 @@ namespace YooAsset
// 3. 检测加载结果 // 3. 检测加载结果
if (Status == EStatus.Checking) if (Status == EStatus.Checking)
{ {
Progress = _cacheRequest.progress;
if (_cacheRequest != null) if (_cacheRequest != null)
{ {
if (IsWaitForAsyncComplete) if (IsWaitForAsyncComplete)
@ -118,11 +119,5 @@ namespace YooAsset
InvokeCompletion(); InvokeCompletion();
} }
} }
public override float GetLoadProgress()
{
if (_cacheRequest == null)
return 0;
return _cacheRequest.progress;
}
} }
} }

View File

@ -40,12 +40,13 @@ namespace YooAsset
/// </summary> /// </summary>
public override DownloadReport GetDownloadReport() public override DownloadReport GetDownloadReport()
{ {
DownloadReport result = OwnerBundle.GetDownloadReport(); DownloadReport result = new DownloadReport();
foreach (var bundleLoader in DependBundleGroup.DependBundles) result.TotalSize = (ulong)OwnerBundle.MainBundleInfo.Bundle.FileSize;
result.DownloadedBytes = OwnerBundle.DownloadedBytes;
foreach (var dependBundle in DependBundleGroup.DependBundles)
{ {
var report = bundleLoader.GetDownloadReport(); result.TotalSize += (ulong)dependBundle.MainBundleInfo.Bundle.FileSize;
result.TotalSize += report.TotalSize; result.DownloadedBytes += dependBundle.DownloadedBytes;
result.DownloadedBytes += report.DownloadedBytes;
} }
result.Progress = result.DownloadedBytes / result.TotalSize; result.Progress = result.DownloadedBytes / result.TotalSize;
return result; return result;

View File

@ -84,6 +84,7 @@ namespace YooAsset
// 3. 检测加载结果 // 3. 检测加载结果
if (Status == EStatus.Checking) if (Status == EStatus.Checking)
{ {
Progress = _asyncOp.progress;
if (_asyncOp.isDone) if (_asyncOp.isDone)
{ {
if (SceneObject.IsValid() && _activateOnLoad) if (SceneObject.IsValid() && _activateOnLoad)
@ -99,11 +100,5 @@ namespace YooAsset
} }
} }
} }
public override float GetLoadProgress()
{
if (_asyncOp == null)
return 0;
return _asyncOp.progress;
}
} }
} }

View File

@ -79,6 +79,7 @@ namespace YooAsset
// 3. 检测加载结果 // 3. 检测加载结果
if (Status == EStatus.Checking) if (Status == EStatus.Checking)
{ {
Progress = _cacheRequest.progress;
if (_cacheRequest != null) if (_cacheRequest != null)
{ {
if (IsWaitForAsyncComplete) if (IsWaitForAsyncComplete)
@ -107,11 +108,5 @@ namespace YooAsset
InvokeCompletion(); InvokeCompletion();
} }
} }
public override float GetLoadProgress()
{
if (_cacheRequest == null)
return 0;
return _cacheRequest.progress;
}
} }
} }

View File

@ -52,6 +52,7 @@ namespace YooAsset
// 2. 检测加载结果 // 2. 检测加载结果
if (Status == EStatus.Checking) if (Status == EStatus.Checking)
{ {
Progress = _asyncOp.progress;
if (_asyncOp.isDone) if (_asyncOp.isDone)
{ {
if (SceneObject.IsValid() && _activateOnLoad) if (SceneObject.IsValid() && _activateOnLoad)
@ -68,11 +69,5 @@ namespace YooAsset
} }
#endif #endif
} }
public override float GetLoadProgress()
{
if (_asyncOp == null)
return 0;
return _asyncOp.progress;
}
} }
} }

View File

@ -63,6 +63,11 @@ namespace YooAsset
/// </summary> /// </summary>
public string LastError { protected set; get; } = string.Empty; public string LastError { protected set; get; } = string.Empty;
/// <summary>
/// 加载进度
/// </summary>
public float Progress { protected set; get; } = 0f;
/// <summary> /// <summary>
/// 引用计数 /// 引用计数
/// </summary> /// </summary>
@ -109,17 +114,6 @@ namespace YooAsset
IsDestroyed = true; IsDestroyed = true;
} }
/// <summary>
/// 获取加载进度
/// </summary>
public virtual float GetLoadProgress()
{
if (IsDone)
return 1f;
else
return 0;
}
/// <summary> /// <summary>
/// 获取下载进度 /// 获取下载进度
/// </summary> /// </summary>
@ -227,6 +221,9 @@ namespace YooAsset
private TaskCompletionSource<object> _taskCompletionSource; private TaskCompletionSource<object> _taskCompletionSource;
protected void InvokeCompletion() protected void InvokeCompletion()
{ {
// 进度百分百完成
Progress = 1f;
// 注意:创建临时列表是为了防止外部逻辑在回调函数内创建或者释放资源句柄。 // 注意:创建临时列表是为了防止外部逻辑在回调函数内创建或者释放资源句柄。
List<OperationHandleBase> tempers = new List<OperationHandleBase>(_handles); List<OperationHandleBase> tempers = new List<OperationHandleBase>(_handles);
foreach (var hande in tempers) foreach (var hande in tempers)

View File

@ -11,17 +11,17 @@ namespace YooAsset
/// <summary> /// <summary>
/// 需要下载的总字节数 /// 需要下载的总字节数
/// </summary> /// </summary>
public long TotalSize; public ulong TotalSize;
/// <summary> /// <summary>
/// 已经下载的字节数 /// 已经下载的字节数
/// </summary> /// </summary>
public long DownloadedBytes; public ulong DownloadedBytes;
public static DownloadReport CreateDefaultReport() public static DownloadReport CreateDefaultReport()
{ {
DownloadReport report = new DownloadReport(); DownloadReport report = new DownloadReport();
report.Progress = 1f; report.Progress = 0f;
report.TotalSize = 0; report.TotalSize = 0;
report.DownloadedBytes = 0; report.DownloadedBytes = 0;
return report; return report;