1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- 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();
- }
- 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();
- });
- }
- }
- }
- }
- }
|