From de1558680c608500f82b15ac8f6331bbf3742bae Mon Sep 17 00:00:00 2001
From: ALEXTANG <574809918@qq.com>
Date: Tue, 9 May 2023 20:47:51 +0800
Subject: [PATCH] [+] Update LoadData
[+] Update LoadData
---
.../HotFix/GameLogic/UI/Common/SafeTop.cs | 21 --
.../Resources/AssetLoad/UILoadTip.prefab | 118 ++++++++++-
.../Resources/AssetLoad/UILoadUpdate.prefab | 13 ++
.../Main/Launcher/Scripts/UI/LoadText.cs | 4 +-
.../Procedure/ProcedureCreateDownloader.cs | 193 ++++++++++++++++--
.../Main/Procedure/ProcedureDownloadFile.cs | 1 +
.../Framework/FrameworkGlobalSettings.cs | 44 +++-
7 files changed, 345 insertions(+), 49 deletions(-)
delete mode 100644 Assets/GameScripts/HotFix/GameLogic/UI/Common/SafeTop.cs
diff --git a/Assets/GameScripts/HotFix/GameLogic/UI/Common/SafeTop.cs b/Assets/GameScripts/HotFix/GameLogic/UI/Common/SafeTop.cs
deleted file mode 100644
index 3e393d16..00000000
--- a/Assets/GameScripts/HotFix/GameLogic/UI/Common/SafeTop.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using UnityEngine;
-using TEngine;
-
-namespace GameLogic
-{
- public class SafeTop : MonoBehaviour
- {
- void Start()
- {
- var topRect = (gameObject.transform as RectTransform);
- var safeArea = UnityEngine.Screen.safeArea;
- if (topRect != null)
- {
- var anchoredPosition = topRect.anchoredPosition;
- anchoredPosition = new Vector2(anchoredPosition.x,anchoredPosition.y - safeArea.y);
- topRect.anchoredPosition = anchoredPosition;
- }
- Log.Debug(safeArea);
- }
- }
-}
diff --git a/Assets/GameScripts/Main/Launcher/Resources/AssetLoad/UILoadTip.prefab b/Assets/GameScripts/Main/Launcher/Resources/AssetLoad/UILoadTip.prefab
index ecb6007f..7053d0fd 100644
--- a/Assets/GameScripts/Main/Launcher/Resources/AssetLoad/UILoadTip.prefab
+++ b/Assets/GameScripts/Main/Launcher/Resources/AssetLoad/UILoadTip.prefab
@@ -466,7 +466,7 @@ RectTransform:
m_GameObject: {fileID: 2640858821944464331}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
- m_LocalScale: {x: 0.5, y: 0.5, z: 0.5}
+ m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 4081528251189279610}
@@ -475,7 +475,7 @@ RectTransform:
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: -42}
- m_SizeDelta: {x: 1060, y: 228}
+ m_SizeDelta: {x: 880, y: 228}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &7673710075172455079
CanvasRenderer:
@@ -507,7 +507,7 @@ MonoBehaviour:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
- m_FontSize: 92
+ m_FontSize: 46
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 4
@@ -546,7 +546,7 @@ RectTransform:
m_GameObject: {fileID: 5302583540007423649}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
- m_LocalScale: {x: 0.5, y: 0.5, z: 0.5}
+ m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 4081528251189279610}
@@ -587,7 +587,7 @@ MonoBehaviour:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
- m_FontSize: 92
+ m_FontSize: 46
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 4
@@ -1006,6 +1006,7 @@ GameObject:
m_Component:
- component: {fileID: 4081528251189279610}
- component: {fileID: 7910362769509927291}
+ - component: {fileID: 7755055850552899157}
- component: {fileID: 3866307299994406820}
m_Layer: 5
m_Name: BgImage
@@ -1046,6 +1047,113 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9108663456504243039}
m_CullTransparentMesh: 0
+--- !u!114 &7755055850552899157
+MonoBehaviour:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 9108663456504243039}
+ m_Enabled: 1
+ m_EditorHideFlags: 0
+ m_Script: {fileID: 11500000, guid: 4d0390bd8b8ffd640b34fe25065ff1df, type: 3}
+ m_Name:
+ m_EditorClassIdentifier:
+ updateType: 0
+ isSpeedBased: 0
+ hasOnStart: 0
+ hasOnPlay: 0
+ hasOnUpdate: 0
+ hasOnStepComplete: 0
+ hasOnComplete: 0
+ hasOnTweenCreated: 0
+ hasOnRewind: 0
+ onStart:
+ m_PersistentCalls:
+ m_Calls: []
+ onPlay:
+ m_PersistentCalls:
+ m_Calls: []
+ onUpdate:
+ m_PersistentCalls:
+ m_Calls: []
+ onStepComplete:
+ m_PersistentCalls:
+ m_Calls: []
+ onComplete:
+ m_PersistentCalls:
+ m_Calls: []
+ onTweenCreated:
+ m_PersistentCalls:
+ m_Calls: []
+ onRewind:
+ m_PersistentCalls:
+ m_Calls: []
+ targetIsSelf: 1
+ targetGO: {fileID: 0}
+ tweenTargetIsTargetGO: 1
+ delay: 0
+ duration: 0.4
+ easeType: 7
+ easeCurve:
+ serializedVersion: 2
+ m_Curve:
+ - serializedVersion: 3
+ time: 0
+ value: 0
+ inSlope: 0
+ outSlope: 0
+ tangentMode: 0
+ weightedMode: 0
+ inWeight: 0
+ outWeight: 0
+ - serializedVersion: 3
+ time: 1
+ value: 1
+ inSlope: 0
+ outSlope: 0
+ tangentMode: 0
+ weightedMode: 0
+ inWeight: 0
+ outWeight: 0
+ m_PreInfinity: 2
+ m_PostInfinity: 2
+ m_RotationOrder: 4
+ loopType: 0
+ loops: 1
+ id:
+ isRelative: 0
+ isFrom: 1
+ isIndependentUpdate: 1
+ autoKill: 1
+ autoGenerate: 1
+ isActive: 1
+ isValid: 1
+ target: {fileID: 4081528251189279610}
+ animationType: 5
+ targetType: 11
+ forcedTargetType: 0
+ autoPlay: 1
+ useTargetAsV3: 0
+ endValueFloat: 0.5
+ endValueV3: {x: 0, y: 0, z: 0}
+ endValueV2: {x: 0, y: 0}
+ endValueColor: {r: 1, g: 1, b: 1, a: 1}
+ endValueString:
+ endValueRect:
+ serializedVersion: 2
+ x: 0
+ y: 0
+ width: 0
+ height: 0
+ endValueTransform: {fileID: 0}
+ optionalBool0: 1
+ optionalBool1: 0
+ optionalFloat0: 0
+ optionalInt0: 0
+ optionalRotationMode: 0
+ optionalScrambleMode: 0
+ optionalString:
--- !u!114 &3866307299994406820
MonoBehaviour:
m_ObjectHideFlags: 0
diff --git a/Assets/GameScripts/Main/Launcher/Resources/AssetLoad/UILoadUpdate.prefab b/Assets/GameScripts/Main/Launcher/Resources/AssetLoad/UILoadUpdate.prefab
index 1c2120ed..2e852a9b 100644
--- a/Assets/GameScripts/Main/Launcher/Resources/AssetLoad/UILoadUpdate.prefab
+++ b/Assets/GameScripts/Main/Launcher/Resources/AssetLoad/UILoadUpdate.prefab
@@ -510,6 +510,7 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 1753386200549547019}
+ - component: {fileID: 281612242691951877}
m_Layer: 5
m_Name: TopNode
m_TagString: Untagged
@@ -540,6 +541,18 @@ RectTransform:
m_AnchoredPosition: {x: 0, y: -100}
m_SizeDelta: {x: 0, y: 200}
m_Pivot: {x: 0.5, y: 0.5}
+--- !u!114 &281612242691951877
+MonoBehaviour:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 4664656392582353123}
+ m_Enabled: 1
+ m_EditorHideFlags: 0
+ m_Script: {fileID: 11500000, guid: 824e3dec0c786894a86848bd990140db, type: 3}
+ m_Name:
+ m_EditorClassIdentifier:
--- !u!1 &7836612998133337201
GameObject:
m_ObjectHideFlags: 0
diff --git a/Assets/GameScripts/Main/Launcher/Scripts/UI/LoadText.cs b/Assets/GameScripts/Main/Launcher/Scripts/UI/LoadText.cs
index 5c421ed6..4ddd3135 100644
--- a/Assets/GameScripts/Main/Launcher/Scripts/UI/LoadText.cs
+++ b/Assets/GameScripts/Main/Launcher/Scripts/UI/LoadText.cs
@@ -7,11 +7,11 @@ namespace GameMain
public string Label_Load_Progress = "正在下载资源文件,请耐心等待\n当前下载速度:{0}/s 资源文件大小:{1}";
public string Label_Load_FirstUnpack = "首次进入游戏,正在初始化游戏资源...(此过程不消耗网络流量)";
public string Label_Load_Unpacking = "正在更新本地资源版本,请耐心等待...(此过程不消耗网络流量)";
- public string Label_Load_Checking = "检测版本文件{0}...";
+ public string Label_Load_Checking = "检测更新设置{0}...";
public string Label_Load_Checked = "最新版本检测完成";
public string Label_Load_Package = "当前使用的版本过低,请下载安装最新版本";
public string Label_Load_Plantform = "当前使用的版本过低,请前往应用商店安装最新版本";
- public string Label_Load_Notice = "检测到可选资源更新,推荐完成更新提升游戏体验";
+ public string Label_Load_Notice = "检测到可选资源更新,更新包大小{0},推荐完成更新提升游戏体验";
public string Label_Load_Force = "检测到版本更新,取消更新将导致无法进入游戏";
public string Label_Load_Force_WIFI =
"检测到有新的游戏内容需要更新,更新包大小{0}, 取消更新将导致无法进入游戏,您当前已为wifi网络,请开始更新";
diff --git a/Assets/GameScripts/Main/Procedure/ProcedureCreateDownloader.cs b/Assets/GameScripts/Main/Procedure/ProcedureCreateDownloader.cs
index 2116f9ad..81f1f055 100644
--- a/Assets/GameScripts/Main/Procedure/ProcedureCreateDownloader.cs
+++ b/Assets/GameScripts/Main/Procedure/ProcedureCreateDownloader.cs
@@ -1,57 +1,222 @@
using System;
+using System.Threading;
using Cysharp.Threading.Tasks;
using TEngine;
+using UnityEngine;
+using UnityEngine.Networking;
+using YooAsset;
using ProcedureOwner = TEngine.IFsm;
+using Utility = TEngine.Utility;
namespace GameMain
{
public class ProcedureCreateDownloader : ProcedureBase
{
+ private int _curTryCount;
+
+ private const int MaxTryCount = 3;
+
public override bool UseNativeDialog { get; }
+ private ProcedureOwner _procedureOwner;
+
+ private ResourceDownloaderOperation _downloader;
+
+ private int _totalDownloadCount;
+
+ private string _totalSizeMb;
+
protected override void OnEnter(ProcedureOwner procedureOwner)
{
+ _procedureOwner = procedureOwner;
+
Log.Info("创建补丁下载器");
UILoadMgr.Show(UIDefine.UILoadUpdate,$"创建补丁下载器...");
- CreateDownloader(procedureOwner).Forget();
+ CreateDownloader().Forget();
}
- private async UniTaskVoid CreateDownloader(ProcedureOwner procedureOwner)
+ private async UniTaskVoid CreateDownloader()
{
await UniTask.Delay(TimeSpan.FromSeconds(0.5f));
- var downloader = GameModule.Resource.CreateResourceDownloader();
+ _downloader = GameModule.Resource.CreateResourceDownloader();
- if (downloader.TotalDownloadCount == 0)
+ if (_downloader.TotalDownloadCount == 0)
{
Log.Info("Not found any download files !");
- ChangeState(procedureOwner);
+ ChangeState(_procedureOwner);
}
else
{
//A total of 10 files were found that need to be downloaded
- Log.Info($"Found total {downloader.TotalDownloadCount} files that need download !");
+ Log.Info($"Found total {_downloader.TotalDownloadCount} files that need download !");
// 发现新更新文件后,挂起流程系统
// 注意:开发者需要在下载前检测磁盘空间不足
- int totalDownloadCount = downloader.TotalDownloadCount;
- long totalDownloadBytes = downloader.TotalDownloadBytes;
+ _totalDownloadCount = _downloader.TotalDownloadCount;
+ long totalDownloadBytes = _downloader.TotalDownloadBytes;
float sizeMb = totalDownloadBytes / 1048576f;
- sizeMb = UnityEngine.Mathf.Clamp(sizeMb, 0.1f, float.MaxValue);
- string totalSizeMb = sizeMb.ToString("f1");
+ sizeMb = Mathf.Clamp(sizeMb, 0.1f, float.MaxValue);
+ _totalSizeMb = sizeMb.ToString("f1");
- UILoadTip.ShowMessageBox($"Found update patch files, Total count {totalDownloadCount} Total size {totalSizeMb}MB", MessageShowType.TwoButton,
+#if false
+ UILoadTip.ShowMessageBox($"Found update patch files, Total count {_totalDownloadCount} Total size {_totalSizeMb}MB", MessageShowType.TwoButton,
LoadStyle.StyleEnum.Style_StartUpdate_Notice
- , () => { StartDownFile(procedureOwner: procedureOwner); }, UnityEngine.Application.Quit);
+ , StartDownFile, Application.Quit);
+#endif
+
+ RequestUpdateData().Forget();
}
}
- void StartDownFile(ProcedureOwner procedureOwner)
+ void StartDownFile()
{
- ChangeState(procedureOwner);
+ ChangeState(_procedureOwner);
+ }
+
+
+ ///
+ /// 请求更新配置数据。
+ ///
+ private async UniTaskVoid RequestUpdateData()
+ {
+ Log.Warning("On RequestVersion");
+ _curTryCount++;
+
+ if (_curTryCount > MaxTryCount)
+ {
+ UILoadTip.ShowMessageBox(LoadText.Instance.Label_Net_Error, MessageShowType.TwoButton,
+ LoadStyle.StyleEnum.Style_Retry,
+ () =>
+ {
+ _curTryCount = 0;
+ RequestUpdateData().Forget();
+ }, Application.Quit);
+ return;
+ }
+
+ var checkVersionUrl = SettingsUtils.GetAppUpdateUrl();
+
+ UILoadMgr.Show(UIDefine.UILoadUpdate, string.Format(LoadText.Instance.Label_Load_Checking, _curTryCount));
+ if (string.IsNullOrEmpty(checkVersionUrl))
+ {
+ Log.Error("LoadMgr.RequestVersion, remote url is empty or null");
+ UILoadTip.ShowMessageBox(LoadText.Instance.Label_RemoteUrlisNull, MessageShowType.OneButton,
+ LoadStyle.StyleEnum.Style_QuitApp,
+ Application.Quit);
+ return;
+ }
+ Log.Info("RequestUpdateData, proxy:" + checkVersionUrl);
+
+ var updateDataStr = await HttpGet(checkVersionUrl);
+
+ try
+ {
+ UpdateData updateData = Utility.Json.ToObject(updateDataStr);
+ ShowUpdateType(updateData);
+ }
+ catch (Exception e)
+ {
+ Log.Fatal(e);
+ throw;
+ }
+ }
+
+ ///
+ /// 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;
+ }
+
+ ///
+ /// 显示更新方式
+ ///
+ ///
+ private void ShowUpdateType(UpdateData data)
+ {
+ UILoadMgr.Show(UIDefine.UILoadUpdate, LoadText.Instance.Label_Load_Checked);
+ //底包更新
+ if (data.UpdateType == UpdateType.PackageUpdate)
+ {
+ UILoadTip.ShowMessageBox(LoadText.Instance.Label_Load_Package, MessageShowType.OneButton,
+ LoadStyle.StyleEnum.Style_DownLoadApk,
+ () =>
+ {
+ Log.Info("自定义下载APK");
+ Application.Quit();
+ });
+ }
+ //资源更新
+ else if (data.UpdateType == UpdateType.ResourceUpdate)
+ {
+ //强制
+ if (data.UpdateStyle == UpdateStyle.Force)
+ {
+ //提示
+ if (data.UpdateNotice == UpdateNotice.Notice)
+ {
+ NetworkReachability networkReachability = Application.internetReachability;
+ string desc = LoadText.Instance.Label_Load_Force_WIFI;
+ if (networkReachability == NetworkReachability.ReachableViaCarrierDataNetwork)
+ {
+ desc = LoadText.Instance.Label_Load_Force_NO_WIFI;
+ }
+ desc = string.Format(desc, $"{_totalSizeMb}MB");
+ UILoadTip.ShowMessageBox(desc, MessageShowType.TwoButton,
+ LoadStyle.StyleEnum.Style_StartUpdate_Notice,
+ StartDownFile, Application.Quit);
+ }
+ //不提示
+ else if (data.UpdateNotice == UpdateNotice.NoNotice)
+ {
+ StartDownFile();
+ }
+ }
+ //非强制
+ else if (data.UpdateStyle == UpdateStyle.Optional)
+ {
+ //提示
+ if (data.UpdateNotice == UpdateNotice.Notice)
+ {
+ UILoadTip.ShowMessageBox(string.Format(LoadText.Instance.Label_Load_Notice,$"{_totalSizeMb}MB"), MessageShowType.TwoButton,
+ LoadStyle.StyleEnum.Style_StartUpdate_Notice,
+ StartDownFile, () =>
+ {
+ ChangeState(_procedureOwner);
+ });
+ }
+ //不提示
+ else if (data.UpdateNotice == UpdateNotice.NoNotice)
+ {
+ StartDownFile();
+ }
+ }
+ else
+ {
+ Log.Error("LoadMgr._CheckUpdate, style is error,code:" + data.UpdateStyle);
+ }
+ }
}
}
}
\ No newline at end of file
diff --git a/Assets/GameScripts/Main/Procedure/ProcedureDownloadFile.cs b/Assets/GameScripts/Main/Procedure/ProcedureDownloadFile.cs
index 1412cec5..3118bdb8 100644
--- a/Assets/GameScripts/Main/Procedure/ProcedureDownloadFile.cs
+++ b/Assets/GameScripts/Main/Procedure/ProcedureDownloadFile.cs
@@ -3,6 +3,7 @@ using Cysharp.Threading.Tasks;
using TEngine;
using YooAsset;
using ProcedureOwner = TEngine.IFsm;
+using Utility = TEngine.Utility;
namespace GameMain
{
diff --git a/Assets/TEngine/Runtime/GameSettings/Framework/FrameworkGlobalSettings.cs b/Assets/TEngine/Runtime/GameSettings/Framework/FrameworkGlobalSettings.cs
index fcea5647..f5ceeb46 100644
--- a/Assets/TEngine/Runtime/GameSettings/Framework/FrameworkGlobalSettings.cs
+++ b/Assets/TEngine/Runtime/GameSettings/Framework/FrameworkGlobalSettings.cs
@@ -2,27 +2,36 @@ using System;
using System.Collections.Generic;
using UnityEngine;
+///
+/// APP更新类型。
+///
public enum UpdateType
{
None = 0,
- //底包更新
- PackageUpdate = 1,
//资源更新
- ResourceUpdate = 2,
+ ResourceUpdate = 1,
+ //底包更新
+ PackageUpdate = 2,
}
+///
+/// 强制更新类型。
+///
public enum UpdateStyle
{
None = 0,
- Froce = 1, //强制
- Optional = 2,//非强制
+ Force = 1, //强制(不更新无法进入游戏。)
+ Optional = 2, //非强制(不更新可以进入游戏。)
}
+///
+/// 是否提示更新。
+///
public enum UpdateNotice
{
None = 0,
- Notice = 1, //提示
- NoNotice = 2,//非提示
+ Notice = 1, //提示
+ NoNotice = 2, //非提示
}
public enum GameStatus
@@ -31,6 +40,27 @@ public enum GameStatus
AssetLoad = 1
}
+///
+/// 版本更新数据。
+///
+public class UpdateData
+{
+ ///
+ /// 是否底包更新。
+ ///
+ public UpdateType UpdateType;
+
+ ///
+ /// 是否强制更新。
+ ///
+ public UpdateStyle UpdateStyle;
+
+ ///
+ /// 是否提示。
+ ///
+ public UpdateNotice UpdateNotice;
+}
+
///
/// 资源存放地
///