mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
简化流程,支持非强制更新,移除冗余UpdateMainFest与UpdateVersion的流程,因为Yoo统一了编辑器单机和联网的流程了。
简化流程,支持非强制更新,移除冗余UpdateMainFest与UpdateVersion的流程,因为Yoo统一了编辑器单机和联网的流程了。
This commit is contained in:
@@ -18,7 +18,7 @@ namespace Procedure
|
||||
LauncherMgr.Show(UIDefine.UILoadUpdate, $"下载完成...");
|
||||
|
||||
// 下载完成之后再保存本地版本。
|
||||
PlayerPrefs.SetString("GAME_VERSION", _resourceModule.PackageVersion);
|
||||
Utility.PlayerPrefs.SetString("GAME_VERSION", _resourceModule.PackageVersion);
|
||||
}
|
||||
|
||||
protected override void OnUpdate(ProcedureOwner procedureOwner, float elapseSeconds, float realElapseSeconds)
|
||||
|
@@ -1,8 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using System.Collections;
|
||||
using Launcher;
|
||||
using TEngine;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
using ProcedureOwner = TEngine.IFsm<TEngine.IProcedureModule>;
|
||||
|
||||
@@ -14,8 +13,12 @@ namespace Procedure
|
||||
|
||||
public override bool UseNativeDialog => true;
|
||||
|
||||
private ProcedureOwner _procedureOwner;
|
||||
|
||||
protected override void OnEnter(ProcedureOwner procedureOwner)
|
||||
{
|
||||
_procedureOwner = procedureOwner;
|
||||
|
||||
base.OnEnter(procedureOwner);
|
||||
|
||||
_initResourcesComplete = false;
|
||||
@@ -26,6 +29,11 @@ namespace Procedure
|
||||
Utility.Unity.StartCoroutine(InitResources(procedureOwner));
|
||||
}
|
||||
|
||||
private void ChangeToCreateDownloaderState(ProcedureOwner procedureOwner)
|
||||
{
|
||||
ChangeState<ProcedureCreateDownloader>(procedureOwner);
|
||||
}
|
||||
|
||||
protected override void OnUpdate(ProcedureOwner procedureOwner, float elapseSeconds, float realElapseSeconds)
|
||||
{
|
||||
base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);
|
||||
@@ -36,25 +44,35 @@ namespace Procedure
|
||||
return;
|
||||
}
|
||||
|
||||
if ((_resourceModule.PlayMode == EPlayMode.HostPlayMode || _resourceModule.PlayMode == EPlayMode.WebPlayMode))
|
||||
if (_resourceModule.PlayMode == EPlayMode.HostPlayMode || _resourceModule.PlayMode == EPlayMode.WebPlayMode)
|
||||
{
|
||||
//线上最新版本operation.PackageVersion
|
||||
Log.Debug($"Updated package Version : from {_resourceModule.GetPackageVersion()} to {_resourceModule.PackageVersion}");
|
||||
ChangeState<ProcedureUpdateManifest>(procedureOwner);
|
||||
//注意:保存资源版本号作为下次默认启动的版本!
|
||||
// 如果当前是WebGL或者是边玩边下载直接进入预加载阶段。
|
||||
if (_resourceModule.PlayMode == EPlayMode.WebPlayMode ||
|
||||
_resourceModule.UpdatableWhilePlaying)
|
||||
{
|
||||
// 边玩边下载还可以拓展首包支持。
|
||||
ChangeToPreloadState(procedureOwner);
|
||||
return;
|
||||
}
|
||||
|
||||
ChangeToCreateDownloaderState(procedureOwner);
|
||||
return;
|
||||
}
|
||||
|
||||
ChangeState<ProcedurePreload>(procedureOwner);
|
||||
ChangeToPreloadState(procedureOwner);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编辑器与单机保持相同流程。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
//// <summary>
|
||||
/// 初始化资源流程。
|
||||
/// <remarks>YooAsset 需要保持编辑器、单机、联机模式流程一致。</remarks>
|
||||
private IEnumerator InitResources(ProcedureOwner procedureOwner)
|
||||
{
|
||||
string packageVersion;
|
||||
|
||||
Log.Info("更新资源清单!!!");
|
||||
LauncherMgr.Show(UIDefine.UILoadUpdate, $"更新清单文件...");
|
||||
|
||||
// 1. 获取资源清单的版本信息
|
||||
var operation1 = _resourceModule.RequestPackageVersionAsync();
|
||||
yield return operation1;
|
||||
@@ -64,11 +82,16 @@ namespace Procedure
|
||||
yield break;
|
||||
}
|
||||
|
||||
packageVersion = operation1.PackageVersion;
|
||||
var packageVersion = operation1.PackageVersion;
|
||||
_resourceModule.PackageVersion = packageVersion;
|
||||
|
||||
|
||||
if (Utility.PlayerPrefs.HasKey("GAME_VERSION"))
|
||||
{
|
||||
Utility.PlayerPrefs.SetString("GAME_VERSION", _resourceModule.PackageVersion);
|
||||
}
|
||||
|
||||
Log.Info($"Init resource package version : {packageVersion}");
|
||||
|
||||
|
||||
// 2. 传入的版本信息更新资源清单
|
||||
var operation2 = _resourceModule.UpdatePackageManifestAsync(packageVersion);
|
||||
yield return operation2;
|
||||
@@ -77,19 +100,75 @@ namespace Procedure
|
||||
OnInitResourcesError(procedureOwner, operation2.Error);
|
||||
yield break;
|
||||
}
|
||||
|
||||
|
||||
_initResourcesComplete = true;
|
||||
}
|
||||
|
||||
|
||||
private void ChangeToPreloadState(ProcedureOwner procedureOwner)
|
||||
{
|
||||
ChangeState<ProcedurePreload>(procedureOwner);
|
||||
}
|
||||
|
||||
private void OnInitResourcesError(ProcedureOwner procedureOwner, string message)
|
||||
{
|
||||
// 检查设备网络连接状态。
|
||||
if (_resourceModule.PlayMode == EPlayMode.HostPlayMode)
|
||||
{
|
||||
if (!IsNeedUpdate())
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error(LoadText.Instance.Label_Net_UnReachable);
|
||||
LauncherMgr.ShowMessageBox(LoadText.Instance.Label_Net_UnReachable, MessageShowType.TwoButton,
|
||||
LoadStyle.StyleEnum.Style_Retry,
|
||||
Application.Quit);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Log.Error(message);
|
||||
LauncherMgr.ShowMessageBox($"初始化资源失败!点击确认重试 \n <color=#FF0000>{message}</color>", MessageShowType.TwoButton,
|
||||
LoadStyle.StyleEnum.Style_Retry
|
||||
, () =>
|
||||
LoadStyle.StyleEnum.Style_Retry, () => { Utility.Unity.StartCoroutine(InitResources(procedureOwner)); }, Application.Quit);
|
||||
}
|
||||
|
||||
private bool IsNeedUpdate()
|
||||
{
|
||||
// 如果不能联网且当前游戏非强制(不更新可以进入游戏。)
|
||||
if (Settings.UpdateSetting.UpdateStyle == UpdateStyle.Optional && !_resourceModule.UpdatableWhilePlaying)
|
||||
{
|
||||
// 获取上次成功记录的版本
|
||||
string packageVersion = Utility.PlayerPrefs.GetString("GAME_VERSION", string.Empty);
|
||||
if (string.IsNullOrEmpty(packageVersion))
|
||||
{
|
||||
Utility.Unity.StartCoroutine(InitResources(procedureOwner));
|
||||
}, UnityEngine.Application.Quit);
|
||||
LauncherMgr.Show(UIDefine.UILoadUpdate, LoadText.Instance.Label_Net_UnReachable);
|
||||
LauncherMgr.ShowMessageBox("没有找到本地版本记录,需要更新资源!", MessageShowType.TwoButton,
|
||||
LoadStyle.StyleEnum.Style_Retry,
|
||||
() => { Utility.Unity.StartCoroutine(InitResources(_procedureOwner)); },
|
||||
Application.Quit);
|
||||
return false;
|
||||
}
|
||||
|
||||
_resourceModule.PackageVersion = packageVersion;
|
||||
|
||||
if (Settings.UpdateSetting.UpdateNotice == UpdateNotice.Notice)
|
||||
{
|
||||
LauncherMgr.Show(UIDefine.UILoadUpdate, LoadText.Instance.Label_Load_Notice);
|
||||
LauncherMgr.ShowMessageBox($"更新失败,检测到可选资源更新,推荐完成更新提升游戏体验! \\n \\n 确定再试一次,取消进入游戏", MessageShowType.TwoButton,
|
||||
LoadStyle.StyleEnum.Style_Retry,
|
||||
() => { Utility.Unity.StartCoroutine(InitResources(_procedureOwner)); },
|
||||
() => { ChangeState<ProcedurePreload>(_procedureOwner); });
|
||||
}
|
||||
else
|
||||
{
|
||||
ChangeState<ProcedurePreload>(_procedureOwner);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,58 +0,0 @@
|
||||
using System;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Launcher;
|
||||
using TEngine;
|
||||
using YooAsset;
|
||||
using ProcedureOwner = TEngine.IFsm<TEngine.IProcedureModule>;
|
||||
|
||||
namespace Procedure
|
||||
{
|
||||
/// <summary>
|
||||
/// 流程 => 用户尝试更新清单
|
||||
/// </summary>
|
||||
public class ProcedureUpdateManifest: ProcedureBase
|
||||
{
|
||||
public override bool UseNativeDialog { get; }
|
||||
|
||||
protected override void OnEnter(ProcedureOwner procedureOwner)
|
||||
{
|
||||
Log.Info("更新资源清单!!!");
|
||||
|
||||
LauncherMgr.Show(UIDefine.UILoadUpdate,$"更新清单文件...");
|
||||
|
||||
UpdateManifest(procedureOwner).Forget();
|
||||
}
|
||||
|
||||
private async UniTaskVoid UpdateManifest(ProcedureOwner procedureOwner)
|
||||
{
|
||||
await UniTask.Delay(TimeSpan.FromSeconds(0.5f));
|
||||
|
||||
var operation = _resourceModule.UpdatePackageManifestAsync(_resourceModule.PackageVersion);
|
||||
|
||||
await operation.ToUniTask();
|
||||
|
||||
if(operation.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
//更新成功
|
||||
//注意:保存资源版本号作为下次默认启动的版本!
|
||||
|
||||
if (_resourceModule.PlayMode == EPlayMode.WebPlayMode ||
|
||||
_resourceModule.UpdatableWhilePlaying)
|
||||
{
|
||||
// 边玩边下载还可以拓展首包支持。
|
||||
ChangeState<ProcedurePreload>(procedureOwner);
|
||||
return;
|
||||
}
|
||||
ChangeState<ProcedureCreateDownloader>(procedureOwner);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error(operation.Error);
|
||||
|
||||
LauncherMgr.ShowMessageBox($"用户尝试更新清单失败!点击确认重试 \n \n <color=#FF0000>原因{operation.Error}</color>", MessageShowType.TwoButton,
|
||||
LoadStyle.StyleEnum.Style_Retry
|
||||
, () => { ChangeState<ProcedureUpdateManifest>(procedureOwner); }, UnityEngine.Application.Quit);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3f0ff55ed6ee4711a65cc396946bb43f
|
||||
timeCreated: 1679634395
|
@@ -1,127 +0,0 @@
|
||||
using System;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Launcher;
|
||||
using UnityEngine;
|
||||
using TEngine;
|
||||
using YooAsset;
|
||||
using ProcedureOwner = TEngine.IFsm<TEngine.IProcedureModule>;
|
||||
|
||||
namespace Procedure
|
||||
{
|
||||
/// <summary>
|
||||
/// 流程 => 用户尝试更新静态版本
|
||||
/// </summary>
|
||||
public class ProcedureUpdateVersion : ProcedureBase
|
||||
{
|
||||
public override bool UseNativeDialog => true;
|
||||
|
||||
private ProcedureOwner _procedureOwner;
|
||||
|
||||
protected override void OnEnter(ProcedureOwner procedureOwner)
|
||||
{
|
||||
_procedureOwner = procedureOwner;
|
||||
|
||||
base.OnEnter(procedureOwner);
|
||||
|
||||
LauncherMgr.Show(UIDefine.UILoadUpdate, $"更新静态版本文件...");
|
||||
|
||||
// 检查设备是否能够访问互联网。
|
||||
if (Application.internetReachability == NetworkReachability.NotReachable)
|
||||
{
|
||||
if (!IsNeedUpdate())
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error("The device is not connected to the network");
|
||||
LauncherMgr.ShowMessageBox(LoadText.Instance.Label_Net_UnReachable, MessageShowType.TwoButton,
|
||||
LoadStyle.StyleEnum.Style_Retry,
|
||||
Application.Quit);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
LauncherMgr.Show(UIDefine.UILoadUpdate, LoadText.Instance.Label_RequestVersionIng);
|
||||
|
||||
// 用户尝试更新静态版本。
|
||||
GetStaticVersion().Forget();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 向用户尝试更新静态版本。
|
||||
/// </summary>
|
||||
private async UniTaskVoid GetStaticVersion()
|
||||
{
|
||||
await UniTask.Delay(TimeSpan.FromSeconds(0.5f));
|
||||
|
||||
var operation = _resourceModule.RequestPackageVersionAsync();
|
||||
|
||||
try
|
||||
{
|
||||
await operation.ToUniTask();
|
||||
|
||||
if (operation.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
//线上最新版本operation.PackageVersion
|
||||
_resourceModule.PackageVersion = operation.PackageVersion;
|
||||
Log.Debug($"Updated package Version : from {_resourceModule.GetPackageVersion()} to {operation.PackageVersion}");
|
||||
ChangeState<ProcedureUpdateManifest>(_procedureOwner);
|
||||
}
|
||||
else
|
||||
{
|
||||
OnGetStaticVersionError(operation.Error);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
OnGetStaticVersionError(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGetStaticVersionError(string error)
|
||||
{
|
||||
Log.Error(error);
|
||||
|
||||
if (!IsNeedUpdate())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
LauncherMgr.ShowMessageBox($"用户尝试更新静态版本失败!点击确认重试 \n \n <color=#FF0000>原因{error}</color>", MessageShowType.TwoButton,
|
||||
LoadStyle.StyleEnum.Style_Retry
|
||||
, () => { ChangeState<ProcedureUpdateVersion>(_procedureOwner); }, UnityEngine.Application.Quit);
|
||||
}
|
||||
|
||||
private bool IsNeedUpdate()
|
||||
{
|
||||
// 如果不能联网且当前游戏非强制(不更新可以进入游戏。)
|
||||
if (Settings.UpdateSetting.UpdateStyle == UpdateStyle.Optional)
|
||||
{
|
||||
Log.Warning("The device is not connected to the network");
|
||||
|
||||
// 获取上次成功记录的版本
|
||||
string packageVersion = PlayerPrefs.GetString("GAME_VERSION", string.Empty);
|
||||
if(string.IsNullOrEmpty(packageVersion))
|
||||
{
|
||||
LauncherMgr.Show(UIDefine.UILoadUpdate, LoadText.Instance.Label_Net_UnReachable);
|
||||
LauncherMgr.ShowMessageBox("没有找到本地版本记录,需要更新资源!", MessageShowType.TwoButton,
|
||||
LoadStyle.StyleEnum.Style_Retry,
|
||||
GetStaticVersion().Forget,
|
||||
Application.Quit);
|
||||
return false;
|
||||
}
|
||||
|
||||
_resourceModule.PackageVersion = packageVersion;
|
||||
|
||||
LauncherMgr.Show(UIDefine.UILoadUpdate, LoadText.Instance.Label_Net_UnReachable);
|
||||
LauncherMgr.ShowMessageBox(LoadText.Instance.Label_Net_UnReachable, MessageShowType.TwoButton,
|
||||
LoadStyle.StyleEnum.Style_Retry,
|
||||
GetStaticVersion().Forget,
|
||||
() => { ChangeState<ProcedureInitResources>(_procedureOwner); });
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6f0ff5df84e44adcb8064f46662a1b10
|
||||
timeCreated: 1665651883
|
@@ -24,6 +24,4 @@ MonoBehaviour:
|
||||
- Procedure.ProcedurePreload
|
||||
- Procedure.ProcedureSplash
|
||||
- Procedure.ProcedureStartGame
|
||||
- Procedure.ProcedureUpdateManifest
|
||||
- Procedure.ProcedureUpdateVersion
|
||||
entranceProcedureTypeName: Procedure.ProcedureLaunch
|
||||
|
@@ -26,7 +26,7 @@ MonoBehaviour:
|
||||
LogicMainDllName: GameLogic.dll
|
||||
AssemblyTextAssetExtension: .bytes
|
||||
AssemblyTextAssetPath: AssetRaw/DLL
|
||||
UpdateStyle: 2
|
||||
UpdateStyle: 1
|
||||
UpdateNotice: 1
|
||||
ResDownLoadPath: http://127.0.0.1:8081
|
||||
FallbackResDownLoadPath: http://127.0.0.1:8082
|
||||
|
Reference in New Issue
Block a user