update operation logic

This commit is contained in:
何冠峰
2024-07-07 16:01:55 +08:00
parent 25231ecd32
commit 260867b588
46 changed files with 525 additions and 678 deletions
@@ -94,8 +94,6 @@ namespace YooAsset
// 等待验证完成
if (_steps == ESteps.CheckVerifyTempFile)
{
// 注意:同步解压文件更新
_verifyOperation.InternalOnUpdate();
if (_verifyOperation.IsDone == false)
return;
@@ -103,21 +101,21 @@ namespace YooAsset
{
if (_fileSystem.WriteCacheFile(Bundle, _tempFilePath))
{
Status = EOperationStatus.Succeed;
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
Error = $"{_fileSystem.GetType().FullName} failed to write file !";
Status = EOperationStatus.Failed;
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"{_fileSystem.GetType().FullName} failed to write file !";
YooLogger.Error(Error);
}
}
else
{
Error = _verifyOperation.Error;
_steps = ESteps.TryAgain;
Error = _verifyOperation.Error;
}
// 注意:验证完成后直接删除文件
@@ -150,23 +148,30 @@ namespace YooAsset
_steps = ESteps.Done;
DisposeWebRequest();
}
public override void WaitForAsyncComplete()
internal override void InternalWaitForAsyncComplete()
{
bool isReuqestLocalFile = IsRequestLocalFile();
while (true)
{
// 文件验证
if (_verifyOperation != null)
_verifyOperation.WaitForAsyncComplete();
// 注意:如果是导入或解压本地文件,执行等待完毕
if (isReuqestLocalFile)
{
if (_verifyOperation.IsDone == false)
_verifyOperation.WaitForAsyncComplete();
InternalOnUpdate();
if (IsDone)
break;
}
else
{
if (ExecuteWhileDone())
{
_steps = ESteps.Done;
break;
}
}
// 驱动流程
InternalOnUpdate();
// 完成后退出
if (IsDone)
break;
}
}
@@ -353,23 +358,30 @@ namespace YooAsset
_steps = ESteps.Done;
DisposeWebRequest();
}
public override void WaitForAsyncComplete()
internal override void InternalWaitForAsyncComplete()
{
bool isReuqestLocalFile = IsRequestLocalFile();
while (true)
{
// 文件验证
if (_verifyOperation != null)
_verifyOperation.WaitForAsyncComplete();
// 注意:如果是导入或解压本地文件,执行等待完毕
if (isReuqestLocalFile)
{
if (_verifyOperation.IsDone == false)
_verifyOperation.WaitForAsyncComplete();
InternalOnUpdate();
if (IsDone)
break;
}
else
{
if (ExecuteWhileDone())
{
_steps = ESteps.Done;
break;
}
}
// 驱动流程
InternalOnUpdate();
// 完成后退出
if (IsDone)
break;
}
}
@@ -159,31 +159,23 @@ namespace YooAsset
}
}
}
public override void WaitForAsyncComplete()
internal override void InternalWaitForAsyncComplete()
{
_isWaitForAsyncComplete = true;
int frame = 1000;
while (true)
{
// 保险机制
// 注意:如果需要从远端下载资源,可能会触发保险机制!
frame--;
if (frame == 0)
if(_downloadFileOp != null)
_downloadFileOp.WaitForAsyncComplete();
if (ExecuteWhileDone())
{
Status = EOperationStatus.Failed;
Error = $"{nameof(WaitForAsyncComplete)} failed ! Try load bundle {_bundle.BundleName} from remote with sync load method !";
if (_downloadFileOp != null && _downloadFileOp.Status == EOperationStatus.Failed)
YooLogger.Error($"Try load bundle {_bundle.BundleName} from remote !");
_steps = ESteps.Done;
YooLogger.Error(Error);
}
// 驱动流程
InternalOnUpdate();
// 完成后退出
if (IsDone)
break;
}
}
}
public override void AbortDownloadOperation()
@@ -299,29 +291,21 @@ namespace YooAsset
}
}
}
public override void WaitForAsyncComplete()
internal override void InternalWaitForAsyncComplete()
{
int frame = 1000;
while (true)
{
// 保险机制
// 注意:如果需要从远端下载资源,可能会触发保险机制!
frame--;
if (frame == 0)
if (_downloadFileOp != null)
_downloadFileOp.WaitForAsyncComplete();
if (ExecuteWhileDone())
{
Status = EOperationStatus.Failed;
Error = $"{nameof(WaitForAsyncComplete)} failed ! Try load bundle {_bundle.BundleName} from remote with sync load method !";
if (_downloadFileOp != null && _downloadFileOp.Status == EOperationStatus.Failed)
YooLogger.Error($"Try load bundle {_bundle.BundleName} from remote !");
_steps = ESteps.Done;
YooLogger.Error(Error);
}
// 驱动流程
InternalOnUpdate();
// 完成后退出
if (IsDone)
break;
}
}
}
public override void AbortDownloadOperation()
@@ -85,14 +85,12 @@ namespace YooAsset
}
}
}
public override void WaitForAsyncComplete()
internal override void InternalWaitForAsyncComplete()
{
while (true)
{
// 驱动流程
// 注意:等待子线程验证文件完毕
InternalOnUpdate();
// 完成后退出
if (IsDone)
break;
}