diff --git a/Assets/GameScripts/Main/Launcher/Resources/AssetLoad/UpdateData.json b/Assets/GameScripts/Main/Launcher/Resources/AssetLoad/UpdateData.json index 45d439cd..5b225e79 100644 --- a/Assets/GameScripts/Main/Launcher/Resources/AssetLoad/UpdateData.json +++ b/Assets/GameScripts/Main/Launcher/Resources/AssetLoad/UpdateData.json @@ -1,5 +1,8 @@ { + "CurrentVersion" : "", "UpdateType": 1, "UpdateStyle": 1, - "UpdateNotice": 1 + "UpdateNotice": 1, + "HostServerURL": "", + "FallbackHostServerURL" : "" } \ No newline at end of file diff --git a/Assets/GameScripts/Main/Procedure/ProcedureCreateDownloader.cs b/Assets/GameScripts/Main/Procedure/ProcedureCreateDownloader.cs index daa23f5c..14114a49 100644 --- a/Assets/GameScripts/Main/Procedure/ProcedureCreateDownloader.cs +++ b/Assets/GameScripts/Main/Procedure/ProcedureCreateDownloader.cs @@ -114,7 +114,7 @@ namespace GameMain } Log.Info("RequestUpdateData, proxy:" + checkVersionUrl); - var updateDataStr = await HttpGet(checkVersionUrl); + var updateDataStr = await Utility.Http.Get(checkVersionUrl); try { @@ -128,30 +128,6 @@ namespace GameMain } } - /// - /// GET请求与获取结果. - /// - public async UniTask 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; - } - /// /// 显示更新方式 /// diff --git a/Assets/GameScripts/Main/Procedure/ProcedureInitPackage.cs b/Assets/GameScripts/Main/Procedure/ProcedureInitPackage.cs index 1177f66f..970a09c8 100644 --- a/Assets/GameScripts/Main/Procedure/ProcedureInitPackage.cs +++ b/Assets/GameScripts/Main/Procedure/ProcedureInitPackage.cs @@ -23,6 +23,23 @@ namespace GameMain 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(); await UniTask.Delay(TimeSpan.FromSeconds(1f)); @@ -82,5 +99,33 @@ namespace GameMain InitPackage(procedureOwner).Forget(); } + + /// + /// 请求更新配置数据。 + /// + private async UniTask 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(updateDataStr); + return updateData; + } + catch (Exception e) + { + Log.Fatal(e); + return null; + } + } } } \ No newline at end of file diff --git a/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Http.cs b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Http.cs new file mode 100644 index 00000000..8f5a32b3 --- /dev/null +++ b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Http.cs @@ -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 + { + /// + /// Http 相关的实用函数。 + /// + public static partial class Http + { + /// + /// GET请求与获取结果。 + /// + public static async UniTask 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; + } + } + } +} \ No newline at end of file diff --git a/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Http.cs.meta b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Http.cs.meta new file mode 100644 index 00000000..3e155e28 --- /dev/null +++ b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Http.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: da0e9fec46234724b7f73d9c49a92603 +timeCreated: 1688475202 \ No newline at end of file diff --git a/Assets/TEngine/Runtime/GameSettings/Framework/FrameworkGlobalSettings.cs b/Assets/TEngine/Runtime/GameSettings/Framework/FrameworkGlobalSettings.cs index 74828714..81e20911 100644 --- a/Assets/TEngine/Runtime/GameSettings/Framework/FrameworkGlobalSettings.cs +++ b/Assets/TEngine/Runtime/GameSettings/Framework/FrameworkGlobalSettings.cs @@ -52,6 +52,11 @@ public enum GameStatus /// public class UpdateData { + /// + /// 当前版本信息。 + /// + public string CurrentVersion; + /// /// 是否底包更新。 /// @@ -66,6 +71,16 @@ public class UpdateData /// 是否提示。 /// public UpdateNotice UpdateNotice; + + /// + /// 热更资源地址。 + /// + public string HostServerURL; + + /// + /// 备用热更资源地址。 + /// + public string FallbackHostServerURL; } ///