2022-04-12 19:15:44 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
|
|
namespace YooAsset
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 更新静态版本操作
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public abstract class UpdateStaticVersionOperation : AsyncOperationBase
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
2022-09-27 21:11:55 +08:00
|
|
|
|
/// 包裹文件的哈希值
|
2022-04-12 19:15:44 +08:00
|
|
|
|
/// </summary>
|
2022-09-27 21:11:55 +08:00
|
|
|
|
public string PackageCRC { protected set; get; } = string.Empty;
|
2022-04-12 19:15:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 编辑器下模拟运行的更新静态版本操作
|
|
|
|
|
|
/// </summary>
|
2022-04-21 16:16:40 +08:00
|
|
|
|
internal sealed class EditorPlayModeUpdateStaticVersionOperation : UpdateStaticVersionOperation
|
2022-04-12 19:15:44 +08:00
|
|
|
|
{
|
|
|
|
|
|
internal override void Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
Status = EOperationStatus.Succeed;
|
|
|
|
|
|
}
|
|
|
|
|
|
internal override void Update()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 离线模式的更新静态版本操作
|
|
|
|
|
|
/// </summary>
|
2022-04-21 16:16:40 +08:00
|
|
|
|
internal sealed class OfflinePlayModeUpdateStaticVersionOperation : UpdateStaticVersionOperation
|
2022-04-12 19:15:44 +08:00
|
|
|
|
{
|
|
|
|
|
|
internal override void Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
Status = EOperationStatus.Succeed;
|
|
|
|
|
|
}
|
|
|
|
|
|
internal override void Update()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2022-08-03 15:46:45 +08:00
|
|
|
|
/// 联机模式的更新静态版本操作
|
2022-04-12 19:15:44 +08:00
|
|
|
|
/// </summary>
|
2022-04-21 16:16:40 +08:00
|
|
|
|
internal sealed class HostPlayModeUpdateStaticVersionOperation : UpdateStaticVersionOperation
|
2022-04-12 19:15:44 +08:00
|
|
|
|
{
|
|
|
|
|
|
private enum ESteps
|
|
|
|
|
|
{
|
|
|
|
|
|
None,
|
|
|
|
|
|
LoadStaticVersion,
|
|
|
|
|
|
CheckStaticVersion,
|
|
|
|
|
|
Done,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static int RequestCount = 0;
|
|
|
|
|
|
private readonly HostPlayModeImpl _impl;
|
2022-09-27 21:11:55 +08:00
|
|
|
|
private readonly string _packageName;
|
2022-04-12 19:15:44 +08:00
|
|
|
|
private readonly int _timeout;
|
|
|
|
|
|
private ESteps _steps = ESteps.None;
|
|
|
|
|
|
private UnityWebDataRequester _downloader;
|
|
|
|
|
|
|
2022-09-27 21:11:55 +08:00
|
|
|
|
internal HostPlayModeUpdateStaticVersionOperation(HostPlayModeImpl impl, string packageName, int timeout)
|
2022-04-12 19:15:44 +08:00
|
|
|
|
{
|
|
|
|
|
|
_impl = impl;
|
2022-09-27 21:11:55 +08:00
|
|
|
|
_packageName = packageName;
|
2022-04-12 19:15:44 +08:00
|
|
|
|
_timeout = timeout;
|
|
|
|
|
|
}
|
|
|
|
|
|
internal override void Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
RequestCount++;
|
|
|
|
|
|
_steps = ESteps.LoadStaticVersion;
|
|
|
|
|
|
}
|
|
|
|
|
|
internal override void Update()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
if (_steps == ESteps.LoadStaticVersion)
|
|
|
|
|
|
{
|
2022-09-27 21:11:55 +08:00
|
|
|
|
string versionFileName = YooAssetSettingsData.GetStaticVersionFileName(_packageName);
|
|
|
|
|
|
string webURL = GetStaticVersionRequestURL(versionFileName);
|
2022-04-12 19:15:44 +08:00
|
|
|
|
YooLogger.Log($"Beginning to request static version : {webURL}");
|
|
|
|
|
|
_downloader = new UnityWebDataRequester();
|
|
|
|
|
|
_downloader.SendRequest(webURL, _timeout);
|
|
|
|
|
|
_steps = ESteps.CheckStaticVersion;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (_steps == ESteps.CheckStaticVersion)
|
|
|
|
|
|
{
|
2022-05-07 20:30:16 +08:00
|
|
|
|
Progress = _downloader.Progress();
|
2022-04-12 19:15:44 +08:00
|
|
|
|
if (_downloader.IsDone() == false)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
if (_downloader.HasError())
|
|
|
|
|
|
{
|
|
|
|
|
|
_steps = ESteps.Done;
|
|
|
|
|
|
Status = EOperationStatus.Failed;
|
|
|
|
|
|
Error = _downloader.GetError();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2022-09-27 21:11:55 +08:00
|
|
|
|
string packageCRC = _downloader.GetText();
|
|
|
|
|
|
if(string.IsNullOrEmpty(packageCRC))
|
2022-04-12 19:15:44 +08:00
|
|
|
|
{
|
|
|
|
|
|
_steps = ESteps.Done;
|
2022-09-27 21:11:55 +08:00
|
|
|
|
Status = EOperationStatus.Failed;
|
|
|
|
|
|
Error = $"URL : {_downloader.URL} Error : static version content is empty.";
|
2022-04-12 19:15:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
2022-05-07 20:30:16 +08:00
|
|
|
|
{
|
2022-09-27 21:11:55 +08:00
|
|
|
|
PackageCRC = packageCRC;
|
2022-04-12 19:15:44 +08:00
|
|
|
|
_steps = ESteps.Done;
|
2022-09-27 21:11:55 +08:00
|
|
|
|
Status = EOperationStatus.Succeed;
|
2022-04-12 19:15:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
_downloader.Dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private string GetStaticVersionRequestURL(string fileName)
|
|
|
|
|
|
{
|
|
|
|
|
|
string url;
|
|
|
|
|
|
|
|
|
|
|
|
// 轮流返回请求地址
|
|
|
|
|
|
if (RequestCount % 2 == 0)
|
|
|
|
|
|
url = _impl.GetPatchDownloadFallbackURL(fileName);
|
|
|
|
|
|
else
|
|
|
|
|
|
url = _impl.GetPatchDownloadMainURL(fileName);
|
|
|
|
|
|
|
|
|
|
|
|
// 注意:在URL末尾添加时间戳
|
|
|
|
|
|
return $"{url}?{System.DateTime.UtcNow.Ticks}";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|