91 lines
2.8 KiB
C#
91 lines
2.8 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using AlicizaX;
|
|
using YooAsset;
|
|
|
|
namespace Unity.Startup.Procedure
|
|
{
|
|
internal sealed class ProcedureInitPackageState : StateBase<UpdateProcedureState>
|
|
{
|
|
private int maxFailedCount = 0;
|
|
|
|
protected override void OnEnter()
|
|
{
|
|
InitPackageAsync().Forget();
|
|
}
|
|
|
|
private async UniTask InitPackageAsync()
|
|
{
|
|
string hostUrl = string.Empty;
|
|
if (GameApp.Resource.PlayMode == EPlayMode.HostPlayMode)
|
|
{
|
|
hostUrl = HttpHelper.CDNUrl;
|
|
}
|
|
|
|
await GameApp.Resource.InitPackageAsync(string.Empty, hostUrl, hostUrl);
|
|
await UniTask.DelayFrame();
|
|
UpdateStaticVersion().Forget();
|
|
}
|
|
|
|
private async UniTask UpdateStaticVersion()
|
|
{
|
|
var buildInOperation = GameApp.Resource.RequestPackageVersionAsync();
|
|
await buildInOperation.ToUniTask();
|
|
|
|
if (buildInOperation.Status == EOperationStatus.Succeed)
|
|
{
|
|
//更新成功
|
|
string packageVersion = buildInOperation.PackageVersion;
|
|
GameApp.Resource.PackageVersion = packageVersion;
|
|
|
|
Log.Info($"Updated package Version : {packageVersion}");
|
|
UpdateManifest().Forget();
|
|
}
|
|
else
|
|
{
|
|
//更新失败
|
|
Log.Error(buildInOperation.Error);
|
|
await UniTask.Delay(3000);
|
|
Log.Info("Retry Update Static Version");
|
|
UpdateStaticVersion().Forget();
|
|
}
|
|
}
|
|
|
|
|
|
private async UniTask UpdateManifest()
|
|
{
|
|
UpdatePackageManifestOperation buildInOperation;
|
|
string packageVersion = "Simulate";
|
|
if (GameApp.Resource.PlayMode != EPlayMode.EditorSimulateMode)
|
|
{
|
|
packageVersion = GameApp.Resource.PackageVersion;
|
|
}
|
|
|
|
buildInOperation = GameApp.Resource.UpdatePackageManifestAsync(packageVersion);
|
|
await buildInOperation.ToUniTask();
|
|
|
|
if (buildInOperation.Status == EOperationStatus.Succeed)
|
|
{
|
|
if (GameApp.Resource.PlayMode == EPlayMode.OfflinePlayMode)
|
|
{
|
|
SwitchState(UpdateProcedureState.ProcedurePatchDoneState);
|
|
return;
|
|
}
|
|
|
|
SwitchState(UpdateProcedureState.ProcedureDownloadBundleState);
|
|
}
|
|
else
|
|
{
|
|
maxFailedCount++;
|
|
Log.Error(buildInOperation.Error);
|
|
if (maxFailedCount >= 3)
|
|
{
|
|
Log.Error(buildInOperation.Error);
|
|
return;
|
|
}
|
|
|
|
UpdateManifest().Forget();
|
|
}
|
|
}
|
|
}
|
|
}
|