mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
[+] Update版本更新时CDN地址也可更新
[+] Update版本更新时CDN地址也可更新
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
{
|
{
|
||||||
|
"CurrentVersion" : "",
|
||||||
"UpdateType": 1,
|
"UpdateType": 1,
|
||||||
"UpdateStyle": 1,
|
"UpdateStyle": 1,
|
||||||
"UpdateNotice": 1
|
"UpdateNotice": 1,
|
||||||
|
"HostServerURL": "",
|
||||||
|
"FallbackHostServerURL" : ""
|
||||||
}
|
}
|
@@ -114,7 +114,7 @@ namespace GameMain
|
|||||||
}
|
}
|
||||||
Log.Info("RequestUpdateData, proxy:" + checkVersionUrl);
|
Log.Info("RequestUpdateData, proxy:" + checkVersionUrl);
|
||||||
|
|
||||||
var updateDataStr = await HttpGet(checkVersionUrl);
|
var updateDataStr = await Utility.Http.Get(checkVersionUrl);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -128,30 +128,6 @@ namespace GameMain
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// GET请求与获取结果.
|
|
||||||
/// </summary>
|
|
||||||
public async UniTask<string> HttpGet(string url,float timeout = 5f)
|
|
||||||
{
|
|
||||||
var cts = new CancellationTokenSource();
|
|
||||||
cts.CancelAfterSlim(TimeSpan.FromSeconds(timeout));
|
|
||||||
|
|
||||||
UnityWebRequest unityWebRequest = UnityWebRequest.Get(url);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await unityWebRequest.SendWebRequest().WithCancellation(cts.Token);
|
|
||||||
}
|
|
||||||
catch (OperationCanceledException ex)
|
|
||||||
{
|
|
||||||
if (ex.CancellationToken == cts.Token)
|
|
||||||
{
|
|
||||||
Debug.Log("HttpGet Timeout");
|
|
||||||
return string.Empty;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return unityWebRequest.downloadHandler.text;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 显示更新方式
|
/// 显示更新方式
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@@ -23,6 +23,23 @@ namespace GameMain
|
|||||||
|
|
||||||
private async UniTaskVoid InitPackage(ProcedureOwner procedureOwner)
|
private async UniTaskVoid InitPackage(ProcedureOwner procedureOwner)
|
||||||
{
|
{
|
||||||
|
if (GameModule.Resource.PlayMode == EPlayMode.HostPlayMode)
|
||||||
|
{
|
||||||
|
UpdateData updateData = await RequestUpdateData();
|
||||||
|
|
||||||
|
if (updateData!=null)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(updateData.HostServerURL))
|
||||||
|
{
|
||||||
|
SettingsUtils.FrameworkGlobalSettings.HostServerURL = updateData.HostServerURL;
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty(updateData.FallbackHostServerURL))
|
||||||
|
{
|
||||||
|
SettingsUtils.FrameworkGlobalSettings.FallbackHostServerURL = updateData.FallbackHostServerURL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var initializationOperation = GameModule.Resource.InitPackage();
|
var initializationOperation = GameModule.Resource.InitPackage();
|
||||||
|
|
||||||
await UniTask.Delay(TimeSpan.FromSeconds(1f));
|
await UniTask.Delay(TimeSpan.FromSeconds(1f));
|
||||||
@@ -82,5 +99,33 @@ namespace GameMain
|
|||||||
|
|
||||||
InitPackage(procedureOwner).Forget();
|
InitPackage(procedureOwner).Forget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 请求更新配置数据。
|
||||||
|
/// </summary>
|
||||||
|
private async UniTask<UpdateData> RequestUpdateData()
|
||||||
|
{
|
||||||
|
var checkVersionUrl = SettingsUtils.GetUpdateDataUrl();
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(checkVersionUrl))
|
||||||
|
{
|
||||||
|
Log.Error("LoadMgr.RequestVersion, remote url is empty or null");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Log.Info("RequestUpdateData, proxy:" + checkVersionUrl);
|
||||||
|
|
||||||
|
var updateDataStr = await Utility.Http.Get(checkVersionUrl);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
UpdateData updateData = Utility.Json.ToObject<UpdateData>(updateDataStr);
|
||||||
|
return updateData;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.Fatal(e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
41
Assets/TEngine/Runtime/GameFramework/Utility/Utility.Http.cs
Normal file
41
Assets/TEngine/Runtime/GameFramework/Utility/Utility.Http.cs
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
using Cysharp.Threading.Tasks;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Networking;
|
||||||
|
|
||||||
|
namespace TEngine
|
||||||
|
{
|
||||||
|
public static partial class Utility
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Http 相关的实用函数。
|
||||||
|
/// </summary>
|
||||||
|
public static partial class Http
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// GET请求与获取结果。
|
||||||
|
/// </summary>
|
||||||
|
public static async UniTask<string> Get(string url,float timeout = 5f)
|
||||||
|
{
|
||||||
|
var cts = new CancellationTokenSource();
|
||||||
|
cts.CancelAfterSlim(TimeSpan.FromSeconds(timeout));
|
||||||
|
|
||||||
|
UnityWebRequest unityWebRequest = UnityWebRequest.Get(url);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await unityWebRequest.SendWebRequest().WithCancellation(cts.Token);
|
||||||
|
}
|
||||||
|
catch (OperationCanceledException ex)
|
||||||
|
{
|
||||||
|
if (ex.CancellationToken == cts.Token)
|
||||||
|
{
|
||||||
|
Debug.Log("HttpGet Timeout");
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return unityWebRequest.downloadHandler.text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: da0e9fec46234724b7f73d9c49a92603
|
||||||
|
timeCreated: 1688475202
|
@@ -52,6 +52,11 @@ public enum GameStatus
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class UpdateData
|
public class UpdateData
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 当前版本信息。
|
||||||
|
/// </summary>
|
||||||
|
public string CurrentVersion;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否底包更新。
|
/// 是否底包更新。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -66,6 +71,16 @@ public class UpdateData
|
|||||||
/// 是否提示。
|
/// 是否提示。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public UpdateNotice UpdateNotice;
|
public UpdateNotice UpdateNotice;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 热更资源地址。
|
||||||
|
/// </summary>
|
||||||
|
public string HostServerURL;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 备用热更资源地址。
|
||||||
|
/// </summary>
|
||||||
|
public string FallbackHostServerURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Reference in New Issue
Block a user