Add progress of async operation
异步操作类增加进度查询。
This commit is contained in:
@@ -145,6 +145,7 @@ namespace YooAsset
|
||||
{
|
||||
_lastDownloadBytes = downloadBytes;
|
||||
_lastDownloadCount = CurrentDownloadCount;
|
||||
Progress = (float)_lastDownloadBytes / TotalDownloadBytes;
|
||||
OnDownloadProgressCallback?.Invoke(TotalDownloadCount, _lastDownloadCount, TotalDownloadBytes, _lastDownloadBytes);
|
||||
}
|
||||
|
||||
|
||||
@@ -108,6 +108,7 @@ namespace YooAsset
|
||||
if (_steps == ESteps.Update)
|
||||
{
|
||||
_appManifestLoader.Update();
|
||||
Progress = _appManifestLoader.Progress();
|
||||
if (_appManifestLoader.IsDone() == false)
|
||||
return;
|
||||
|
||||
@@ -181,6 +182,7 @@ namespace YooAsset
|
||||
if (_steps == ESteps.Update)
|
||||
{
|
||||
_appManifestLoader.Update();
|
||||
Progress = _appManifestLoader.Progress();
|
||||
if (_appManifestLoader.IsDone() == false)
|
||||
return;
|
||||
|
||||
@@ -243,6 +245,16 @@ namespace YooAsset
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载进度
|
||||
/// </summary>
|
||||
public float Progress()
|
||||
{
|
||||
if (_downloader2 == null)
|
||||
return 0;
|
||||
return _downloader2.Progress();
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (IsDone())
|
||||
|
||||
@@ -172,6 +172,7 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.UpdateVerifyingCache)
|
||||
{
|
||||
Progress = GetVerifyProgress();
|
||||
if (UpdateVerifyingCache())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
@@ -258,6 +259,7 @@ namespace YooAsset
|
||||
private readonly List<PatchBundle> _verifyingList = new List<PatchBundle>(100);
|
||||
private readonly ThreadSyncContext _syncContext = new ThreadSyncContext();
|
||||
private int _verifyMaxNum = 32;
|
||||
private int _verifyTotalCount = 0;
|
||||
private int _verifySuccessCount = 0;
|
||||
private int _verifyFailCount = 0;
|
||||
|
||||
@@ -290,6 +292,7 @@ namespace YooAsset
|
||||
ThreadPool.GetMaxThreads(out int workerThreads, out int ioThreads);
|
||||
YooLogger.Log($"Work threads : {workerThreads}, IO threads : {ioThreads}");
|
||||
_verifyMaxNum = Math.Min(workerThreads, ioThreads);
|
||||
_verifyTotalCount = _waitingList.Count;
|
||||
}
|
||||
private bool UpdateVerifyingCache()
|
||||
{
|
||||
@@ -358,6 +361,12 @@ namespace YooAsset
|
||||
}
|
||||
_verifyingList.Remove(info.Bundle);
|
||||
}
|
||||
private float GetVerifyProgress()
|
||||
{
|
||||
if (_verifyTotalCount == 0)
|
||||
return 1f;
|
||||
return (float)(_verifySuccessCount + _verifyFailCount) / _verifyTotalCount;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -111,6 +111,7 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.CheckWebManifest)
|
||||
{
|
||||
Progress = _downloaderManifest.Progress();
|
||||
if (_downloaderManifest.IsDone() == false)
|
||||
return;
|
||||
|
||||
|
||||
@@ -87,6 +87,7 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.CheckStaticVersion)
|
||||
{
|
||||
Progress = _downloader.Progress();
|
||||
if (_downloader.IsDone() == false)
|
||||
return;
|
||||
|
||||
@@ -105,7 +106,7 @@ namespace YooAsset
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"URL : {_downloader.URL} Error : static version content is invalid.";
|
||||
|
||||
Reference in New Issue
Block a user