using System;
using System.Collections.Generic;
using TEngine.Runtime.HotUpdate;
using UnityEngine;
using UnityEngine.Networking;
namespace TEngine.Runtime
{
///
/// 流程加载器 - 检查版本更新
///
public class ProcedureCheckVersion:ProcedureBase
{
private bool m_CheckVersionComplete = false;
private bool m_NeedUpdateVersion = false;
private OnlineVersionInfo m_VersionInfo = null;
private UnityWebRequest m_UnityWebRequest;
private UnityWebRequestAsyncOperation m_result;
private int _curTryCount;
private const int MaxTryCount = 3;
private void PreLoadHotUpdate()
{
//热更新阶段文本初始化
LoadText.Instance.InitConfigData(null);
//热更新UI初始化
UILoadMgr.Initialize();
UILoadMgr.Show(UIDefine.UILoadUpdate);
}
protected override void OnEnter(IFsm procedureOwner)
{
base.OnEnter(procedureOwner);
m_CheckVersionComplete = false;
m_NeedUpdateVersion = false;
m_VersionInfo = null;
PreLoadHotUpdate();
RequestVersion();
}
///
/// 请求热更数据
///
private void RequestVersion()
{
_curTryCount++;
if (_curTryCount > MaxTryCount)
{
LoaderUtilities.ShowMessageBox(LoadText.Instance.Label_Net_Error, MessageShowType.TwoButton,
LoadStyle.StyleEnum.Style_Retry,
() => {
_curTryCount = 0;
RequestVersion();
}, () =>
{
Application.Quit();
});
return;
}
var checkVersionUrl = Utility.Text.Format(HotUpdateMgr.Instance.BuildInfo.CheckVersionUrl,
GetPlatformPath());
UILoadMgr.Show(UIDefine.UILoadUpdate, string.Format(LoadText.Instance.Label_Load_Checking, _curTryCount));
if (string.IsNullOrEmpty(checkVersionUrl))
{
TLogger.LogError("LoadMgr.RequestVersion, remote url is empty or null");
LoaderUtilities.ShowMessageBox(LoadText.Instance.Label_RemoteUrlisNull, MessageShowType.OneButton,
LoadStyle.StyleEnum.Style_QuitApp,
Application.Quit);
return;
}
TLogger.LogInfo("LoadMgr.RequestVersion, proxy:" + checkVersionUrl);
Log.Info($"Check Version Url=>{checkVersionUrl}");
m_UnityWebRequest = UnityWebRequest.Get(checkVersionUrl);
m_result = m_UnityWebRequest.SendWebRequest();
}
private LoadData GenLoadData()
{
var onlineResListUrl = m_VersionInfo.UpdatePrefixUri + "/" + m_VersionInfo.ResourceVersion +"/";
Log.Warning(onlineResListUrl);
string resListStr = string.Empty;
try
{
resListStr = LoaderUtilities.HttpGet(onlineResListUrl + "Md5List.json");
}
catch (Exception e)
{
LoaderUtilities.ShowMessageBox(LoadText.Instance.Label_Net_Error+e.Message, MessageShowType.TwoButton,
LoadStyle.StyleEnum.Style_Retry,
() => {
RequestVersion();
}, () =>
{
Application.Quit();
});
return null;
}
var resDic = (Dictionary)MiniJSON.Json.Deserialize(resListStr);
List