12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- using System.Collections;
- using UniFramework.Pooling;
- using UnityEngine;
- using YooAsset;
- namespace GFGGame
- {
- public class HotUpdateDriver: MonoBehaviour
- {
- private void Awake()
- {
- //UniFramework
- // 初始化对象池系统
- UniPooling.Initalize();
- //Litjson
- LitJson.UnityTypeBindings.Register();
- //ET
- ETManager.Instance.Init();
- //Game
- OperationSystem.Initialize();
- GameController.Start();
- Reporter reporter = GameObject.Find("Reporter").GetComponent<Reporter>();
- if(LauncherConfig.ChannelId != (int)ChannelID.Test && reporter != null)
- {
- reporter.numOfCircleToShow = 50;
- }
- }
- private void Update()
- {
- OperationSystem.Update();
- CheckExitAlert();
- }
- private void OnDestroy()
- {
- OperationSystem.DestroyAll();
- }
- private void OnApplicationQuit()
- {
- SQLiteHelper.Instance.CloseConnection(true);
- }
- private void CheckExitAlert()
- {
- if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.Home))
- {
- QDManager.Exit();
- }
- }
- private long pauseTime;
- private void OnApplicationPause(bool pause)
- {
- if(pause)
- {
- pauseTime = ET.TimeHelper.ClientNowSeconds();
- }
- else
- {
- if(ET.TimeHelper.ClientNowSeconds() - pauseTime > 180 || LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL)
- {
- StartCoroutine(CheckVersion(VersionController.DefaultPackage));
- }
- }
- }
- private IEnumerator CheckVersion(string packageName)
- {
- var package = YooAssets.GetPackage(packageName);
- string oldVersion = package.GetPackageVersion();
- var operation = package.UpdatePackageVersionAsync();
- yield return operation;
- if (operation.Status == EOperationStatus.Succeed)
- {
- VersionController.Instance.PackageVersion = operation.PackageVersion;
- LogUtil.LogDev($"版本对比: {oldVersion} {operation.PackageVersion}");
- if(!operation.PackageVersion.Equals(oldVersion))
- {
- AlertSystem.Show("游戏已有更新,您可以立即重启游戏获取最佳游戏体验,也可以稍后重启更新。")
- .SetLeftButton(true, "稍后更新")
- .SetRightButton(true, "重启游戏", (obj)=>
- {
- Application.Quit();
- });
- }
- }
- }
- }
- }
|