mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
[+] HotUpdateProcedure
[+] HotUpdateProcedure
This commit is contained in:
@@ -0,0 +1,182 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.UI;
|
||||
using TEngine;
|
||||
|
||||
namespace GameMain
|
||||
{
|
||||
#pragma warning disable CS0649
|
||||
public class LoadStyle : MonoBehaviour
|
||||
{
|
||||
public Button _btn_ignore;
|
||||
public Button _btn_update;
|
||||
public Button _btn_package;
|
||||
|
||||
public Text _label_ignore;
|
||||
public Text _label_update;
|
||||
public Text _label_package;
|
||||
private Dictionary<StyleEnum, Dictionary<BtnEnum, StyleItem>> loadConfig;
|
||||
|
||||
private const string ConfigPath = "RawBytes/UIStyle/Style.json";
|
||||
|
||||
public enum StyleEnum
|
||||
{
|
||||
Style_Default = 0,//默认
|
||||
Style_QuitApp = 1,//退出应用
|
||||
Style_RestartApp = 2,//重启应用
|
||||
Style_Retry = 3,//重试
|
||||
Style_StartUpdate_Notice = 4,//提示更新
|
||||
Style_DownLoadApk = 5,//下载底包
|
||||
Style_Clear = 6,//修复客户端
|
||||
Style_DownZip = 7,//继续下载压缩包
|
||||
}
|
||||
|
||||
public enum BtnEnum
|
||||
{
|
||||
BtnOK = 0, //确定按钮
|
||||
BtnIgnore = 1,//取消按钮
|
||||
BtnOther = 2, //其他按钮
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 单个按钮的样式
|
||||
/// </summary>
|
||||
private class StyleItem
|
||||
{
|
||||
public Alignment Align;//对其方式
|
||||
public bool Show;//是否隐藏
|
||||
public string Desc;//按钮描述
|
||||
}
|
||||
/// <summary>
|
||||
/// 对齐方式
|
||||
/// </summary>
|
||||
private enum Alignment
|
||||
{
|
||||
Left = 0,
|
||||
Middle = 1,
|
||||
Right = 2
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
//设置按钮的默认描述
|
||||
_label_ignore.text = LoadText.Instance.Label_Btn_Ignore;
|
||||
_label_update.text = LoadText.Instance.Label_Btn_Update;
|
||||
_label_package.text = LoadText.Instance.Label_Btn_Package;
|
||||
|
||||
InitConfig();
|
||||
}
|
||||
|
||||
private void InitConfig()
|
||||
{
|
||||
// string url = AssetUtility.Config.GetConfigAsset(ConfigPath);
|
||||
// if (!String.IsNullOrEmpty(url))
|
||||
// {
|
||||
// string finalPath = SetFilePath(url);
|
||||
// InitConfigDic(finalPath);
|
||||
// }
|
||||
}
|
||||
|
||||
#region 初始化配置文件
|
||||
private string SetFilePath(string path)
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
if (path.StartsWith(Application.persistentDataPath))
|
||||
path = $"file://{path}";
|
||||
#elif UNITY_IOS
|
||||
if (path.StartsWith(Application.persistentDataPath)||path.StartsWith(Application.streamingAssetsPath))
|
||||
path = $"file://{path}";
|
||||
#endif
|
||||
return path;
|
||||
}
|
||||
|
||||
private void InitConfigDic(string path)
|
||||
{
|
||||
UnityWebRequest www = UnityWebRequest.Get(path);
|
||||
UnityWebRequestAsyncOperation request = www.SendWebRequest();
|
||||
while (!request.isDone)
|
||||
{
|
||||
}
|
||||
|
||||
if (!String.IsNullOrEmpty(www.downloadHandler.text))
|
||||
{
|
||||
loadConfig = JsonConvert.DeserializeObject<Dictionary<StyleEnum, Dictionary<BtnEnum, StyleItem>>>(www.downloadHandler.text);
|
||||
}
|
||||
www.Dispose();
|
||||
}
|
||||
#endregion
|
||||
/// <summary>
|
||||
/// 设置样式
|
||||
/// </summary>
|
||||
/// <param name="type">样式对应的id</param>
|
||||
public void SetStyle(StyleEnum type)
|
||||
{
|
||||
if (type == StyleEnum.Style_Default)
|
||||
return;
|
||||
|
||||
if (loadConfig == null)
|
||||
{
|
||||
Log.Error("LoadConfig is null");
|
||||
return;
|
||||
}
|
||||
|
||||
var style = loadConfig[type];
|
||||
if (style == null)
|
||||
{
|
||||
Log.Error($"LoadConfig, Can not find type:{type},please check it");
|
||||
return;
|
||||
}
|
||||
SetButtonStyle(style);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置按钮的描述,是否隐藏
|
||||
/// </summary>
|
||||
private void SetButtonStyle(Dictionary<BtnEnum, StyleItem> list)
|
||||
{
|
||||
foreach (var item in list)
|
||||
{
|
||||
switch (item.Key)
|
||||
{
|
||||
case BtnEnum.BtnOK:
|
||||
_label_update.text = item.Value.Desc;
|
||||
_btn_update.gameObject.SetActive(item.Value.Show);
|
||||
SetButtonPos(item.Value.Align, _btn_update.transform);
|
||||
break;
|
||||
case BtnEnum.BtnIgnore:
|
||||
_label_ignore.text = item.Value.Desc;
|
||||
_btn_ignore.gameObject.SetActive(item.Value.Show);
|
||||
SetButtonPos(item.Value.Align, _btn_ignore.transform);
|
||||
break;
|
||||
case BtnEnum.BtnOther:
|
||||
_label_package.text = item.Value.Desc;
|
||||
_btn_package.gameObject.SetActive(item.Value.Show);
|
||||
SetButtonPos(item.Value.Align, _btn_package.transform);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置按钮位置
|
||||
/// </summary>
|
||||
private void SetButtonPos(Alignment align, Transform item)
|
||||
{
|
||||
switch (align)
|
||||
{
|
||||
case Alignment.Left:
|
||||
item.SetSiblingIndex(0);
|
||||
break;
|
||||
case Alignment.Middle:
|
||||
item.SetSiblingIndex(1);
|
||||
break;
|
||||
case Alignment.Right:
|
||||
item.SetSiblingIndex(2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c56a1db52fd64134881893a68f6e1371
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,136 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace GameMain
|
||||
{
|
||||
public class TextMode
|
||||
{
|
||||
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_Checked = "最新版本检测完成";
|
||||
public string Label_Load_Package = "当前使用的版本过低,请下载安装最新版本";
|
||||
public string Label_Load_Plantform = "当前使用的版本过低,请前往应用商店安装最新版本";
|
||||
public string Label_Load_Notice = "检测到可选资源更新,推荐完成更新提升游戏体验";
|
||||
public string Label_Load_Force = "检测到版本更新,取消更新将导致无法进入游戏";
|
||||
public string Label_Load_Force_WIFI =
|
||||
"检测到有新的游戏内容需要更新,更新包大小<color=#BA3026>{0}</color>, 取消更新将导致无法进入游戏,您当前已为<color=#BA3026>wifi网络</color>,请开始更新";
|
||||
public string Label_Load_Force_NO_WIFI =
|
||||
"检测到有新的游戏内容需要更新,更新包大小<color=#BA3026>{0}</color>, 取消更新将导致无法进入游戏,请开始更新";
|
||||
public string Label_Load_Error = "更新参数错误{0},请点击确定重新启动游戏";
|
||||
public string Label_Load_FirstEntrerGame_Error = "首次进入游戏资源异常";
|
||||
public string Label_Load_UnpackComplete = "正在加载最新资源文件...(此过程不消耗网络流量)";
|
||||
public string Label_Load_UnPackError = "资源解压失败,请点击确定重新启动游戏";
|
||||
public string Label_Load_Load_Progress = "正在载入...{0}%";
|
||||
public string Label_Load_Download_Progress = "正在下载...{0}%";
|
||||
public string Label_Load_Init = "初始化...";
|
||||
public string Label_Net_UnReachable = "当前网络不可用,请检查本地网络设置后点击确认进行重试";
|
||||
public string Label_Net_ReachableViaCarrierDataNetwork = "当前是移动网络,是否继续下载";
|
||||
public string Label_Net_Error = "网络异常,请重试";
|
||||
public string Label_Net_Changed = "网络切换,正在尝试重连,{0}次";
|
||||
public string Label_Data_Empty = "数据异常";
|
||||
public string Label_Memory_Low = "初始化资源加载失败,请检查本地内存是否充足";
|
||||
public string Label_Memory_Low_Load = "内存是否充足,无法更新";
|
||||
public string Label_Memory_UnZip_Low = "内存不足,无法解压";
|
||||
public string Label_App_id = "APPVer {0}";//"游戏版本号:{0}";
|
||||
public string Label_Res_id = "ResVer {0}";//"资源版本号:{0}";
|
||||
public string Label_Clear_Comfirm = "是否清理本地资源?(清理完成后会关闭游戏且重新下载最新资源)";
|
||||
public string Label_RestartApp = "本次更新需要重启应用,请点击确定重新启动游戏";
|
||||
public string Label_DownLoadFailed = "网络太慢,是否继续下载";
|
||||
public string Label_ClearConfig = "清除环境配置,需要重启应用";
|
||||
public string Label_RegionInfoIllegal = "区服信息为空";
|
||||
public string Label_RemoteUrlisNull = "热更地址为空";
|
||||
public string Label_FirstPackageNotFound = "首包资源加载失败";
|
||||
public string Label_RequestReginInfo = "正在请求区服信息{0}次";
|
||||
public string Label_RequestTimeOut = "请求区服信息超时,是否重试?";
|
||||
public string Label_Region_ArgumentError = "参数错误";
|
||||
public string Label_Region_IndexOutOfRange = "索引越界";
|
||||
public string Label_Region_NonConfigApplication = "未配置此应用";
|
||||
public string Label_Region_SystemError = "系统异常";
|
||||
public string Label_PreventionOfAddiction = "著作人权:XX市TEngine有限公司 软著登记号:2022SR0000000\n抵制不良游戏,拒绝盗版游戏。注意自我保护,谨防受骗上当。适度游戏益脑," +
|
||||
"沉迷游戏伤身。合理安排时间,享受健康生活。";
|
||||
public string Label_Btn_Update = "确定";
|
||||
public string Label_Btn_Ignore = "取消";
|
||||
public string Label_Btn_Package = "更新";
|
||||
|
||||
public string Label_Dlc_ConfigVerificateStage = "配置校验中...";
|
||||
public string Label_Dlc_ConfigLoadingStage = "下载配置中...";
|
||||
public string Label_Dlc_AssetsLoading = "下载资源中...";
|
||||
public string Label_Dlc_LoadingFinish = "下载结束";
|
||||
|
||||
public string Label_Dlc_Load_Force_WIFI =
|
||||
"检测到有新的游戏内容需要更新, 取消更新将导致无法进入游戏,您当前已为<color=#BA3026>wifi网络</color>,请开始更新";
|
||||
public string Label_Dlc_Load_Force_NO_WIFI =
|
||||
"检测到有新的游戏内容需要更新, 取消更新将导致无法进入游戏,请开始更新";
|
||||
|
||||
public string Label_Had_Update = "检测到有版本更新...";
|
||||
public string Label_RequestVersionIng = "正在向服务器请求版本信息中...";
|
||||
public string Label_RequestVersionInfo = "正在向服务器请求版本信息{0}次";
|
||||
}
|
||||
|
||||
public class LoadText : TextMode
|
||||
{
|
||||
private static LoadText _instance;
|
||||
|
||||
public static LoadText Instance
|
||||
{
|
||||
get { return _instance ?? (_instance = new LoadText()); }
|
||||
}
|
||||
|
||||
public void InitConfigData(TextAsset asset)
|
||||
{
|
||||
if (asset == null)
|
||||
return;
|
||||
|
||||
TextMode loadConfig = JsonUtility.FromJson<TextMode>(asset.text);
|
||||
if (loadConfig != null)
|
||||
{
|
||||
Label_Load_Progress = loadConfig.Label_Load_Progress;
|
||||
Label_Load_FirstUnpack = loadConfig.Label_Load_FirstUnpack;
|
||||
Label_Load_Unpacking = loadConfig.Label_Load_Unpacking;
|
||||
Label_Load_Checking = loadConfig.Label_Load_Checking;
|
||||
Label_Load_Checked = loadConfig.Label_Load_Checked;
|
||||
Label_Load_Package = loadConfig.Label_Load_Package;
|
||||
Label_Load_Plantform = loadConfig.Label_Load_Plantform;
|
||||
Label_Load_Notice = loadConfig.Label_Load_Notice;
|
||||
Label_Load_Force = loadConfig.Label_Load_Force;
|
||||
Label_Load_Force_WIFI = loadConfig.Label_Load_Force_WIFI;
|
||||
Label_Load_Force_NO_WIFI = loadConfig.Label_Load_Force_NO_WIFI;
|
||||
Label_Load_Error = loadConfig.Label_Load_Error;
|
||||
Label_Load_FirstEntrerGame_Error = loadConfig.Label_Load_FirstEntrerGame_Error;
|
||||
Label_Load_UnpackComplete = loadConfig.Label_Load_UnpackComplete;
|
||||
Label_Load_UnPackError = loadConfig.Label_Load_UnPackError;
|
||||
Label_Load_Load_Progress = loadConfig.Label_Load_Load_Progress;
|
||||
Label_Load_Download_Progress = loadConfig.Label_Load_Download_Progress;
|
||||
Label_Load_Init = loadConfig.Label_Load_Init;
|
||||
Label_Net_UnReachable = loadConfig.Label_Net_UnReachable;
|
||||
Label_Net_Error = loadConfig.Label_Net_Error;
|
||||
Label_Net_Changed = loadConfig.Label_Net_Changed;
|
||||
Label_Data_Empty = loadConfig.Label_Data_Empty;
|
||||
Label_Memory_Low = loadConfig.Label_Memory_Low;
|
||||
Label_Memory_Low_Load = loadConfig.Label_Memory_Low_Load;
|
||||
Label_Memory_UnZip_Low = loadConfig.Label_Memory_UnZip_Low;
|
||||
Label_App_id = loadConfig.Label_App_id;
|
||||
Label_Res_id = loadConfig.Label_Res_id;
|
||||
Label_Clear_Comfirm = loadConfig.Label_Clear_Comfirm;
|
||||
Label_RestartApp = loadConfig.Label_RestartApp;
|
||||
Label_DownLoadFailed = loadConfig.Label_DownLoadFailed;
|
||||
Label_ClearConfig = loadConfig.Label_ClearConfig;
|
||||
Label_PreventionOfAddiction = loadConfig.Label_PreventionOfAddiction;
|
||||
Label_RegionInfoIllegal = loadConfig.Label_RegionInfoIllegal;
|
||||
Label_RemoteUrlisNull = loadConfig.Label_RemoteUrlisNull;
|
||||
Label_FirstPackageNotFound = loadConfig.Label_FirstPackageNotFound;
|
||||
Label_RequestReginInfo = loadConfig.Label_RequestReginInfo;
|
||||
Label_Net_ReachableViaCarrierDataNetwork = loadConfig.Label_Net_ReachableViaCarrierDataNetwork;
|
||||
Label_RequestTimeOut = loadConfig.Label_RequestTimeOut;
|
||||
Label_Region_ArgumentError = loadConfig.Label_Region_ArgumentError;
|
||||
Label_Region_IndexOutOfRange = loadConfig.Label_Region_IndexOutOfRange;
|
||||
Label_Region_NonConfigApplication = loadConfig.Label_Region_NonConfigApplication;
|
||||
Label_Region_SystemError = loadConfig.Label_Region_SystemError;
|
||||
Label_Btn_Ignore = loadConfig.Label_Btn_Ignore;
|
||||
Label_Btn_Package = loadConfig.Label_Btn_Package;
|
||||
Label_Btn_Update = loadConfig.Label_Btn_Update;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 26b25172848a83441b2cfadd771152ea
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
|
||||
namespace GameMain
|
||||
{
|
||||
public class LoadUpdateLogic
|
||||
{
|
||||
private static LoadUpdateLogic _instance;
|
||||
|
||||
public Action<int> DownloadCompleteAction = null;
|
||||
public Action<float> DownProgressAction = null;
|
||||
public Action<bool,GameStatus> UnpackedCompleteAction = null;
|
||||
public Action<float,GameStatus> UnpackedProgressAction = null;
|
||||
|
||||
public static LoadUpdateLogic Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new LoadUpdateLogic();
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4c7fe9e5620ac5d4bae49fbd58746210
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace GameMain
|
||||
{
|
||||
public class UIBase : MonoBehaviour
|
||||
{
|
||||
protected object Param;
|
||||
public virtual void OnEnter(object param)
|
||||
{
|
||||
Param = param;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b150d874e1db306419683d8fb8f50af4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,34 @@
|
||||
using System.Collections.Generic;
|
||||
using TEngine;
|
||||
|
||||
namespace GameMain
|
||||
{
|
||||
public class UIDefine
|
||||
{
|
||||
public static readonly string UILoadUpdate = "UILoadUpdate";
|
||||
public static readonly string UILoadTip = "UILoadTip";
|
||||
|
||||
/// <summary>
|
||||
/// 注册ui
|
||||
/// </summary>
|
||||
/// <param name="list"></param>
|
||||
public static void RegisterUI(Dictionary<string, string> list)
|
||||
{
|
||||
if (list == null)
|
||||
{
|
||||
Log.Error("[UIManager]list is null");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!list.ContainsKey(UILoadUpdate))
|
||||
{
|
||||
list.Add(UILoadUpdate, $"AssetLoad/{UILoadUpdate}");
|
||||
}
|
||||
|
||||
if (!list.ContainsKey(UILoadTip))
|
||||
{
|
||||
list.Add(UILoadTip, $"AssetLoad/{UILoadTip}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8b4a6ad67f754024987f55526fa21034
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,149 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TEngine;
|
||||
|
||||
namespace GameMain
|
||||
{
|
||||
public static class UILoadMgr
|
||||
{
|
||||
private static GameObject _uiLoad;
|
||||
private static readonly Dictionary<string, string> UIList = new Dictionary<string, string>();
|
||||
private static readonly Dictionary<string, UIBase> UIMap = new Dictionary<string, UIBase>();
|
||||
/// <summary>
|
||||
/// 初始化根节点
|
||||
/// </summary>
|
||||
public static void Initialize()
|
||||
{
|
||||
_uiLoad = GameObject.Find("AssetLoad");
|
||||
if (_uiLoad == null)
|
||||
{
|
||||
var obj = Resources.Load($"AssetLoad/UILoad");
|
||||
if (obj == null)
|
||||
{
|
||||
Log.Error("Failed to load UILoad. Please check the resource path");
|
||||
return;
|
||||
}
|
||||
_uiLoad = Object.Instantiate(obj) as GameObject;
|
||||
if (_uiLoad != null)
|
||||
{
|
||||
_uiLoad.name = "AssetLoad";
|
||||
_uiLoad.transform.SetAsLastSibling();
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error($"AssetLoad object Instantiate Failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
RegisterUI();
|
||||
}
|
||||
|
||||
private static void RegisterUI()
|
||||
{
|
||||
UIDefine.RegisterUI(UIList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// show ui
|
||||
/// </summary>
|
||||
/// <param name="uiInfo">对应的ui</param>
|
||||
/// <param name="param">参数</param>
|
||||
public static void Show(string uiInfo,object param = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(uiInfo))
|
||||
return;
|
||||
|
||||
if (!UIList.ContainsKey(uiInfo))
|
||||
{
|
||||
Log.Error($"not define ui:{uiInfo}");
|
||||
return;
|
||||
}
|
||||
|
||||
GameObject ui = null;
|
||||
if (!UIMap.ContainsKey(uiInfo))
|
||||
{
|
||||
Object obj = Resources.Load(UIList[uiInfo]);
|
||||
if (obj != null)
|
||||
{
|
||||
ui = Object.Instantiate(obj) as GameObject;
|
||||
if (ui != null)
|
||||
{
|
||||
ui.transform.SetParent(_uiLoad.transform);
|
||||
ui.transform.localScale = Vector3.one;
|
||||
ui.transform.localPosition = Vector3.zero;
|
||||
RectTransform rect = ui.GetComponent<RectTransform>();
|
||||
rect.sizeDelta = Vector2.zero;
|
||||
}
|
||||
}
|
||||
|
||||
if (ui != null)
|
||||
{
|
||||
UIBase uiBase = ui.GetComponent<UIBase>();
|
||||
if (uiBase != null)
|
||||
{
|
||||
UIMap.Add(uiInfo, uiBase);
|
||||
}
|
||||
}
|
||||
}
|
||||
UIMap[uiInfo].gameObject.SetActive(true);
|
||||
if (param != null)
|
||||
{
|
||||
UIBase component = UIMap[uiInfo].GetComponent<UIBase>();
|
||||
if (component != null)
|
||||
{
|
||||
component.OnEnter(param);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 隐藏ui对象
|
||||
/// </summary>
|
||||
/// <param name="uiName">对应的ui</param>
|
||||
public static void Hide(string uiName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(uiName))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!UIMap.ContainsKey(uiName))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
UIMap[uiName].gameObject.SetActive(false);
|
||||
Object.DestroyImmediate(UIMap[uiName].gameObject);
|
||||
UIMap.Remove(uiName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取显示的ui对象
|
||||
/// </summary>
|
||||
/// <param name="ui"></param>
|
||||
/// <returns></returns>
|
||||
public static UIBase GetActiveUI(string ui)
|
||||
{
|
||||
return UIMap.ContainsKey(ui) ? UIMap[ui] : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 隐藏ui管理器
|
||||
/// </summary>
|
||||
public static void HideAll()
|
||||
{
|
||||
foreach (var item in UIMap)
|
||||
{
|
||||
if (item.Value && item.Value.gameObject)
|
||||
{
|
||||
item.Value.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
UIMap.Clear();
|
||||
|
||||
if (_uiLoad != null)
|
||||
{
|
||||
Object.Destroy(_uiLoad);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6381a0f5db6b61948a8fcb8176d8019b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,134 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System;
|
||||
using TEngine;
|
||||
using TMPro;
|
||||
|
||||
namespace GameMain
|
||||
{
|
||||
public enum MessageShowType
|
||||
{
|
||||
None = 0,
|
||||
OneButton = 1,
|
||||
TwoButton = 2,
|
||||
ThreeButton = 3,
|
||||
}
|
||||
|
||||
public class UILoadTip : UIBase
|
||||
{
|
||||
public Button _btn_update;
|
||||
public Button _btn_ignore;
|
||||
public Button _btn_package;
|
||||
public TextMeshProUGUI _label_desc;
|
||||
public TextMeshProUGUI _label_tittle;
|
||||
|
||||
public Action OnOk;
|
||||
public Action OnCancle;
|
||||
public MessageShowType Showtype = MessageShowType.None;
|
||||
|
||||
void Start()
|
||||
{
|
||||
EventTriggerListener.Get(_btn_update.gameObject).OnClick = _OnGameUpdate;
|
||||
EventTriggerListener.Get(_btn_ignore.gameObject).OnClick = _OnGameIgnor;
|
||||
EventTriggerListener.Get(_btn_package.gameObject).OnClick = _OnInvoke;
|
||||
}
|
||||
|
||||
public override void OnEnter(object data)
|
||||
{
|
||||
_btn_ignore.gameObject.SetActive(false);
|
||||
_btn_package.gameObject.SetActive(false);
|
||||
_btn_update.gameObject.SetActive(false);
|
||||
switch (Showtype)
|
||||
{
|
||||
case MessageShowType.OneButton:
|
||||
_btn_update.gameObject.SetActive(true);
|
||||
break;
|
||||
case MessageShowType.TwoButton:
|
||||
_btn_update.gameObject.SetActive(true);
|
||||
_btn_ignore.gameObject.SetActive(true);
|
||||
break;
|
||||
case MessageShowType.ThreeButton:
|
||||
_btn_ignore.gameObject.SetActive(true);
|
||||
_btn_package.gameObject.SetActive(true);
|
||||
_btn_package.gameObject.SetActive(true);
|
||||
break;
|
||||
}
|
||||
|
||||
_label_desc.text = data.ToString();
|
||||
}
|
||||
|
||||
private void _OnGameUpdate(GameObject obj)
|
||||
{
|
||||
if (OnOk == null)
|
||||
{
|
||||
_label_desc.text = "<color=#BA3026>该按钮不应该存在</color>";
|
||||
}
|
||||
else
|
||||
{
|
||||
OnOk();
|
||||
_OnClose();
|
||||
}
|
||||
}
|
||||
|
||||
private void _OnGameIgnor(GameObject obj)
|
||||
{
|
||||
if (OnCancle == null)
|
||||
{
|
||||
_label_desc.text = "<color=#BA3026>该按钮不应该存在</color>";
|
||||
}
|
||||
else
|
||||
{
|
||||
OnCancle();
|
||||
_OnClose();
|
||||
}
|
||||
}
|
||||
|
||||
private void _OnInvoke(GameObject obj)
|
||||
{
|
||||
if (OnOk == null)
|
||||
{
|
||||
_label_desc.text = "<color=#BA3026>该按钮不应该存在</color>";
|
||||
}
|
||||
else
|
||||
{
|
||||
OnOk();
|
||||
_OnClose();
|
||||
}
|
||||
}
|
||||
|
||||
private void _OnClose()
|
||||
{
|
||||
UILoadMgr.Hide(UIDefine.UILoadTip);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 显示提示框,目前最多支持三个按钮
|
||||
/// </summary>
|
||||
/// <param name="desc">描述</param>
|
||||
/// <param name="showtype">类型(MessageShowType)</param>
|
||||
/// <param name="style">StyleEnum</param>
|
||||
/// <param name="onOk">点击事件</param>
|
||||
/// <param name="onCancel">取消事件</param>
|
||||
/// <param name="onPackage">更新事件</param>
|
||||
public static void ShowMessageBox(string desc, MessageShowType showtype = MessageShowType.OneButton,
|
||||
LoadStyle.StyleEnum style = LoadStyle.StyleEnum.Style_Default,
|
||||
Action onOk = null,
|
||||
Action onCancel = null,
|
||||
Action onPackage = null)
|
||||
{
|
||||
UILoadMgr.Show(UIDefine.UILoadTip, desc);
|
||||
var ui = UILoadMgr.GetActiveUI(UIDefine.UILoadTip) as UILoadTip;
|
||||
if (ui == null) return;
|
||||
ui.OnOk = onOk;
|
||||
ui.OnCancle = onCancel;
|
||||
ui.Showtype = showtype;
|
||||
ui.OnEnter(desc);
|
||||
|
||||
var loadStyleUI = ui.GetComponent<LoadStyle>();
|
||||
if (loadStyleUI)
|
||||
{
|
||||
loadStyleUI.SetStyle(style);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d32acf4f4a006a4986b0c39320a1a99
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,138 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TEngine;
|
||||
|
||||
namespace GameMain
|
||||
{
|
||||
public class UILoadUpdate : UIBase
|
||||
{
|
||||
[SerializeField] public Button _btn_clear;
|
||||
[SerializeField] public Scrollbar _obj_progress;
|
||||
[SerializeField] public Text _label_desc;
|
||||
[SerializeField] public Text _label_appid;
|
||||
[SerializeField] public Text _label_resid;
|
||||
|
||||
public virtual void Start()
|
||||
{
|
||||
EventTriggerListener.Get(_btn_clear.gameObject).OnClick = OnClear;
|
||||
_btn_clear.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public virtual void OnEnable()
|
||||
{
|
||||
LoadUpdateLogic.Instance.DownloadCompleteAction += DownLoad_Complete_Action;
|
||||
LoadUpdateLogic.Instance.DownProgressAction += DownLoad_Progress_Action;
|
||||
LoadUpdateLogic.Instance.UnpackedCompleteAction += Unpacked_Complete_Action;
|
||||
LoadUpdateLogic.Instance.UnpackedProgressAction += Unpacked_Progress_Action;
|
||||
RefreshVersion();
|
||||
}
|
||||
|
||||
public override void OnEnter(object param)
|
||||
{
|
||||
base.OnEnter(param);
|
||||
_label_desc.text = param.ToString();
|
||||
RefreshVersion();
|
||||
}
|
||||
|
||||
public virtual void Update()
|
||||
{
|
||||
}
|
||||
|
||||
private void RefreshVersion()
|
||||
{
|
||||
_label_appid.text = string.Format(LoadText.Instance.Label_App_id, Version.GameVersion);
|
||||
_label_resid.text = string.Format(LoadText.Instance.Label_Res_id, GameModule.Resource.PackageVersion);
|
||||
}
|
||||
|
||||
public virtual void OnContinue(GameObject obj)
|
||||
{
|
||||
// LoadMgr.Instance.StartDownLoad();
|
||||
}
|
||||
|
||||
public virtual void OnStop(GameObject obj)
|
||||
{
|
||||
// LoadMgr.Instance.StopDownLoad();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空本地缓存
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
public virtual void OnClear(GameObject obj)
|
||||
{
|
||||
OnStop(null);
|
||||
UILoadTip.ShowMessageBox(LoadText.Instance.Label_Clear_Comfirm, MessageShowType.TwoButton,
|
||||
LoadStyle.StyleEnum.Style_Clear,
|
||||
() =>
|
||||
{
|
||||
GameModule.Resource.ClearSandbox();
|
||||
Application.Quit();
|
||||
}, () => { OnContinue(null); });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载进度完成
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
public virtual void DownLoad_Complete_Action(int type)
|
||||
{
|
||||
Log.Info("DownLoad_Complete");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载进度更新
|
||||
/// </summary>
|
||||
/// <param name="progress"></param>
|
||||
public virtual void DownLoad_Progress_Action(float progress)
|
||||
{
|
||||
_obj_progress.gameObject.SetActive(true);
|
||||
|
||||
_obj_progress.size = progress;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解压缩完成回调
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="status"></param>
|
||||
public virtual void Unpacked_Complete_Action(bool type, GameStatus status)
|
||||
{
|
||||
_obj_progress.gameObject.SetActive(true);
|
||||
_label_desc.text = LoadText.Instance.Label_Load_UnpackComplete;
|
||||
if (status == GameStatus.AssetLoad)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error("error type");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解压缩进度更新
|
||||
/// </summary>
|
||||
/// <param name="progress"></param>
|
||||
/// <param name="status"></param>
|
||||
public virtual void Unpacked_Progress_Action(float progress, GameStatus status)
|
||||
{
|
||||
_obj_progress.gameObject.SetActive(true);
|
||||
if (status == GameStatus.First)
|
||||
{
|
||||
_label_desc.text = LoadText.Instance.Label_Load_FirstUnpack;
|
||||
}
|
||||
else
|
||||
{
|
||||
_label_desc.text = LoadText.Instance.Label_Load_Unpacking;
|
||||
}
|
||||
|
||||
_obj_progress.size = progress;
|
||||
}
|
||||
|
||||
public virtual void OnDisable()
|
||||
{
|
||||
OnStop(null);
|
||||
LoadUpdateLogic.Instance.DownloadCompleteAction -= DownLoad_Complete_Action;
|
||||
LoadUpdateLogic.Instance.DownProgressAction -= DownLoad_Progress_Action;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f0fad7cbc10b815488c9e6ebfeccb210
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user