123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
-
- namespace YooAsset
- {
- internal abstract class DownloaderBase
- {
- protected enum ESteps
- {
- None,
- CheckLocalFile,
- CreateDownload,
- CheckDownload,
- TryAgain,
- Succeed,
- Failed,
- }
- protected readonly BundleInfo _bundleInfo;
- protected ESteps _steps = ESteps.None;
- protected int _timeout;
- protected int _failedTryAgain;
- protected int _requestCount;
- protected string _requestURL;
- protected string _lastError = string.Empty;
- protected float _downloadProgress = 0f;
- protected ulong _downloadedBytes = 0;
-
-
-
- public float DownloadProgress
- {
- get { return _downloadProgress; }
- }
-
-
-
- public ulong DownloadedBytes
- {
- get { return _downloadedBytes; }
- }
- public DownloaderBase(BundleInfo bundleInfo)
- {
- _bundleInfo = bundleInfo;
- }
- public void SendRequest(int failedTryAgain, int timeout)
- {
- if (_steps == ESteps.None)
- {
- _failedTryAgain = failedTryAgain;
- _timeout = timeout;
- _steps = ESteps.CheckLocalFile;
- }
- }
- public abstract void Update();
- public abstract void Abort();
-
-
-
- protected string GetRequestURL()
- {
-
- _requestCount++;
- if (_requestCount % 2 == 0)
- return _bundleInfo.RemoteFallbackURL;
- else
- return _bundleInfo.RemoteMainURL;
- }
-
-
-
- public BundleInfo GetBundleInfo()
- {
- return _bundleInfo;
- }
-
-
-
- public bool IsDone()
- {
- return _steps == ESteps.Succeed || _steps == ESteps.Failed;
- }
-
-
-
- public bool HasError()
- {
- return _steps == ESteps.Failed;
- }
-
-
-
- public void ReportError()
- {
- YooLogger.Error(GetLastError());
- }
-
-
-
- public void ReportWarning()
- {
- YooLogger.Warning(GetLastError());
- }
-
-
-
- public string GetLastError()
- {
- return $"Failed to download : {_requestURL} Error : {_lastError}";
- }
- }
- }
|