public override void Abort() { if (IsDone() == false) { _steps = ESteps.Failed; _lastError = "user abort"; if (_threadDownloader != null) { _threadDownloader.Abort(); _threadDownloader = null; } } }
public override void Update() { if (_steps == ESteps.None) { return; } if (IsDone()) { return; } if (_steps == ESteps.CreateDownload) { // 重置变量 _downloadProgress = 0f; _downloadedBytes = 0; _tryAgainTimer = 0f; _requestURL = GetRequestURL(); _threadDownloader = new ThreadDownloader(); _threadDownloader.Run(_requestURL, _bundleInfo.GetCacheLoadPath(), _bundleInfo.Hash, _bundleInfo.CRC, _bundleInfo.SizeBytes, _timeout); _steps = ESteps.CheckDownload; } if (_steps == ESteps.CheckDownload) { _downloadProgress = _threadDownloader.DownloadProgress; _downloadedBytes = _threadDownloader.DownloadedBytes; if (_threadDownloader.IsDone == false) { return; } if (_threadDownloader.HasError()) { _lastError = _threadDownloader.Error; // 失败后重新尝试 if (_failedTryAgain > 0) { ReportWarning(); _steps = ESteps.TryAgain; } else { ReportError(); _steps = ESteps.Failed; } } else { DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.BundleName); _steps = ESteps.Succeed; } } // 重新尝试下载 if (_steps == ESteps.TryAgain) { _tryAgainTimer += UnityEngine.Time.unscaledDeltaTime; if (_tryAgainTimer > 1f) { _failedTryAgain--; _steps = ESteps.CreateDownload; YooLogger.Warning($"Try again download : {_requestURL}"); } } }