[+] Update LoadData

[+] Update LoadData
This commit is contained in:
ALEXTANG
2023-05-09 20:47:51 +08:00
parent 079ff980a3
commit de1558680c
7 changed files with 345 additions and 49 deletions

View File

@@ -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);
}
}
}

View File

@@ -466,7 +466,7 @@ RectTransform:
m_GameObject: {fileID: 2640858821944464331} m_GameObject: {fileID: 2640858821944464331}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0} 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_ConstrainProportionsScale: 0
m_Children: [] m_Children: []
m_Father: {fileID: 4081528251189279610} m_Father: {fileID: 4081528251189279610}
@@ -475,7 +475,7 @@ RectTransform:
m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: -42} 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} m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &7673710075172455079 --- !u!222 &7673710075172455079
CanvasRenderer: CanvasRenderer:
@@ -507,7 +507,7 @@ MonoBehaviour:
m_Calls: [] m_Calls: []
m_FontData: m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 92 m_FontSize: 46
m_FontStyle: 0 m_FontStyle: 0
m_BestFit: 0 m_BestFit: 0
m_MinSize: 4 m_MinSize: 4
@@ -546,7 +546,7 @@ RectTransform:
m_GameObject: {fileID: 5302583540007423649} m_GameObject: {fileID: 5302583540007423649}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0} 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_ConstrainProportionsScale: 0
m_Children: [] m_Children: []
m_Father: {fileID: 4081528251189279610} m_Father: {fileID: 4081528251189279610}
@@ -587,7 +587,7 @@ MonoBehaviour:
m_Calls: [] m_Calls: []
m_FontData: m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 92 m_FontSize: 46
m_FontStyle: 0 m_FontStyle: 0
m_BestFit: 0 m_BestFit: 0
m_MinSize: 4 m_MinSize: 4
@@ -1006,6 +1006,7 @@ GameObject:
m_Component: m_Component:
- component: {fileID: 4081528251189279610} - component: {fileID: 4081528251189279610}
- component: {fileID: 7910362769509927291} - component: {fileID: 7910362769509927291}
- component: {fileID: 7755055850552899157}
- component: {fileID: 3866307299994406820} - component: {fileID: 3866307299994406820}
m_Layer: 5 m_Layer: 5
m_Name: BgImage m_Name: BgImage
@@ -1046,6 +1047,113 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9108663456504243039} m_GameObject: {fileID: 9108663456504243039}
m_CullTransparentMesh: 0 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 --- !u!114 &3866307299994406820
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@@ -510,6 +510,7 @@ GameObject:
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 1753386200549547019} - component: {fileID: 1753386200549547019}
- component: {fileID: 281612242691951877}
m_Layer: 5 m_Layer: 5
m_Name: TopNode m_Name: TopNode
m_TagString: Untagged m_TagString: Untagged
@@ -540,6 +541,18 @@ RectTransform:
m_AnchoredPosition: {x: 0, y: -100} m_AnchoredPosition: {x: 0, y: -100}
m_SizeDelta: {x: 0, y: 200} m_SizeDelta: {x: 0, y: 200}
m_Pivot: {x: 0.5, y: 0.5} 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 --- !u!1 &7836612998133337201
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@@ -7,11 +7,11 @@ namespace GameMain
public string Label_Load_Progress = "正在下载资源文件,请耐心等待\n当前下载速度{0}/s 资源文件大小:{1}"; public string Label_Load_Progress = "正在下载资源文件,请耐心等待\n当前下载速度{0}/s 资源文件大小:{1}";
public string Label_Load_FirstUnpack = "首次进入游戏,正在初始化游戏资源...(此过程不消耗网络流量)"; public string Label_Load_FirstUnpack = "首次进入游戏,正在初始化游戏资源...(此过程不消耗网络流量)";
public string Label_Load_Unpacking = "正在更新本地资源版本,请耐心等待...(此过程不消耗网络流量)"; 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_Checked = "最新版本检测完成";
public string Label_Load_Package = "当前使用的版本过低,请下载安装最新版本"; public string Label_Load_Package = "当前使用的版本过低,请下载安装最新版本";
public string Label_Load_Plantform = "当前使用的版本过低,请前往应用商店安装最新版本"; public string Label_Load_Plantform = "当前使用的版本过低,请前往应用商店安装最新版本";
public string Label_Load_Notice = "检测到可选资源更新,推荐完成更新提升游戏体验"; public string Label_Load_Notice = "检测到可选资源更新,更新包大小<color=#BA3026>{0}</color>,推荐完成更新提升游戏体验";
public string Label_Load_Force = "检测到版本更新,取消更新将导致无法进入游戏"; public string Label_Load_Force = "检测到版本更新,取消更新将导致无法进入游戏";
public string Label_Load_Force_WIFI = public string Label_Load_Force_WIFI =
"检测到有新的游戏内容需要更新,更新包大小<color=#BA3026>{0}</color>, 取消更新将导致无法进入游戏,您当前已为<color=#BA3026>wifi网络</color>,请开始更新"; "检测到有新的游戏内容需要更新,更新包大小<color=#BA3026>{0}</color>, 取消更新将导致无法进入游戏,您当前已为<color=#BA3026>wifi网络</color>,请开始更新";

View File

@@ -1,57 +1,222 @@
using System; using System;
using System.Threading;
using Cysharp.Threading.Tasks; using Cysharp.Threading.Tasks;
using TEngine; using TEngine;
using UnityEngine;
using UnityEngine.Networking;
using YooAsset;
using ProcedureOwner = TEngine.IFsm<TEngine.IProcedureManager>; using ProcedureOwner = TEngine.IFsm<TEngine.IProcedureManager>;
using Utility = TEngine.Utility;
namespace GameMain namespace GameMain
{ {
public class ProcedureCreateDownloader : ProcedureBase public class ProcedureCreateDownloader : ProcedureBase
{ {
private int _curTryCount;
private const int MaxTryCount = 3;
public override bool UseNativeDialog { get; } public override bool UseNativeDialog { get; }
private ProcedureOwner _procedureOwner;
private ResourceDownloaderOperation _downloader;
private int _totalDownloadCount;
private string _totalSizeMb;
protected override void OnEnter(ProcedureOwner procedureOwner) protected override void OnEnter(ProcedureOwner procedureOwner)
{ {
_procedureOwner = procedureOwner;
Log.Info("创建补丁下载器"); Log.Info("创建补丁下载器");
UILoadMgr.Show(UIDefine.UILoadUpdate,$"创建补丁下载器..."); 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)); 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 !"); Log.Info("Not found any download files !");
ChangeState<ProcedureDownloadOver>(procedureOwner); ChangeState<ProcedureDownloadOver>(_procedureOwner);
} }
else else
{ {
//A total of 10 files were found that need to be downloaded //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; _totalDownloadCount = _downloader.TotalDownloadCount;
long totalDownloadBytes = downloader.TotalDownloadBytes; long totalDownloadBytes = _downloader.TotalDownloadBytes;
float sizeMb = totalDownloadBytes / 1048576f; float sizeMb = totalDownloadBytes / 1048576f;
sizeMb = UnityEngine.Mathf.Clamp(sizeMb, 0.1f, float.MaxValue); sizeMb = Mathf.Clamp(sizeMb, 0.1f, float.MaxValue);
string totalSizeMb = sizeMb.ToString("f1"); _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 LoadStyle.StyleEnum.Style_StartUpdate_Notice
, () => { StartDownFile(procedureOwner: procedureOwner); }, UnityEngine.Application.Quit); , StartDownFile, Application.Quit);
#endif
RequestUpdateData().Forget();
} }
} }
void StartDownFile(ProcedureOwner procedureOwner) void StartDownFile()
{ {
ChangeState<ProcedureDownloadFile>(procedureOwner); ChangeState<ProcedureDownloadFile>(_procedureOwner);
}
/// <summary>
/// 请求更新配置数据。
/// </summary>
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<UpdateData>(updateDataStr);
ShowUpdateType(updateData);
}
catch (Exception e)
{
Log.Fatal(e);
throw;
}
}
/// <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>
/// <returns></returns>
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<ProcedureLoadAssembly>(_procedureOwner);
});
}
//不提示
else if (data.UpdateNotice == UpdateNotice.NoNotice)
{
StartDownFile();
}
}
else
{
Log.Error("LoadMgr._CheckUpdate, style is error,code:" + data.UpdateStyle);
}
}
} }
} }
} }

View File

@@ -3,6 +3,7 @@ using Cysharp.Threading.Tasks;
using TEngine; using TEngine;
using YooAsset; using YooAsset;
using ProcedureOwner = TEngine.IFsm<TEngine.IProcedureManager>; using ProcedureOwner = TEngine.IFsm<TEngine.IProcedureManager>;
using Utility = TEngine.Utility;
namespace GameMain namespace GameMain
{ {

View File

@@ -2,27 +2,36 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
/// <summary>
/// APP更新类型。
/// </summary>
public enum UpdateType public enum UpdateType
{ {
None = 0, None = 0,
//底包更新
PackageUpdate = 1,
//资源更新 //资源更新
ResourceUpdate = 2, ResourceUpdate = 1,
//底包更新
PackageUpdate = 2,
} }
/// <summary>
/// 强制更新类型。
/// </summary>
public enum UpdateStyle public enum UpdateStyle
{ {
None = 0, None = 0,
Froce = 1, //强制 Force = 1, //强制(不更新无法进入游戏。)
Optional = 2,//非强制 Optional = 2, //非强制(不更新可以进入游戏。)
} }
/// <summary>
/// 是否提示更新。
/// </summary>
public enum UpdateNotice public enum UpdateNotice
{ {
None = 0, None = 0,
Notice = 1, //提示 Notice = 1, //提示
NoNotice = 2,//非提示 NoNotice = 2, //非提示
} }
public enum GameStatus public enum GameStatus
@@ -31,6 +40,27 @@ public enum GameStatus
AssetLoad = 1 AssetLoad = 1
} }
/// <summary>
/// 版本更新数据。
/// </summary>
public class UpdateData
{
/// <summary>
/// 是否底包更新。
/// </summary>
public UpdateType UpdateType;
/// <summary>
/// 是否强制更新。
/// </summary>
public UpdateStyle UpdateStyle;
/// <summary>
/// 是否提示。
/// </summary>
public UpdateNotice UpdateNotice;
}
/// <summary> /// <summary>
/// 资源存放地 /// 资源存放地
/// </summary> /// </summary>