Update runtime logic

This commit is contained in:
hevinci
2022-09-27 21:11:55 +08:00
parent e1801a5fba
commit af37bb6e54
13 changed files with 176 additions and 307 deletions
@@ -9,9 +9,9 @@ namespace YooAsset
public abstract class UpdateStaticVersionOperation : AsyncOperationBase
{
/// <summary>
/// 资源版本号
/// 包裹文件的哈希值
/// </summary>
public int ResourceVersion { protected set; get; } = 0;
public string PackageCRC { protected set; get; } = string.Empty;
}
/// <summary>
@@ -57,13 +57,15 @@ namespace YooAsset
private static int RequestCount = 0;
private readonly HostPlayModeImpl _impl;
private readonly string _packageName;
private readonly int _timeout;
private ESteps _steps = ESteps.None;
private UnityWebDataRequester _downloader;
internal HostPlayModeUpdateStaticVersionOperation(HostPlayModeImpl impl, int timeout)
internal HostPlayModeUpdateStaticVersionOperation(HostPlayModeImpl impl, string packageName, int timeout)
{
_impl = impl;
_packageName = packageName;
_timeout = timeout;
}
internal override void Start()
@@ -78,7 +80,8 @@ namespace YooAsset
if (_steps == ESteps.LoadStaticVersion)
{
string webURL = GetStaticVersionRequestURL(YooAssetSettings.VersionFileName);
string versionFileName = YooAssetSettingsData.GetStaticVersionFileName(_packageName);
string webURL = GetStaticVersionRequestURL(versionFileName);
YooLogger.Log($"Beginning to request static version : {webURL}");
_downloader = new UnityWebDataRequester();
_downloader.SendRequest(webURL, _timeout);
@@ -99,17 +102,18 @@ namespace YooAsset
}
else
{
if (int.TryParse(_downloader.GetText(), out int value))
{
ResourceVersion = value;
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
string packageCRC = _downloader.GetText();
if(string.IsNullOrEmpty(packageCRC))
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"URL : {_downloader.URL} Error : static version content is invalid.";
Error = $"URL : {_downloader.URL} Error : static version content is empty.";
}
else
{
PackageCRC = packageCRC;
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
}
_downloader.Dispose();