HotUpdateDriver.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using System.Collections;
  2. using UniFramework.Pooling;
  3. using UnityEngine;
  4. using YooAsset;
  5. namespace GFGGame
  6. {
  7. public class HotUpdateDriver: MonoBehaviour
  8. {
  9. private void Awake()
  10. {
  11. //UniFramework
  12. // 初始化对象池系统
  13. UniPooling.Initalize();
  14. //Litjson
  15. LitJson.UnityTypeBindings.Register();
  16. //ET
  17. ETManager.Instance.Init();
  18. //Game
  19. OperationSystem.Initialize();
  20. GameController.Start();
  21. }
  22. private void Update()
  23. {
  24. OperationSystem.Update();
  25. CheckExitAlert();
  26. }
  27. private void OnDestroy()
  28. {
  29. OperationSystem.DestroyAll();
  30. }
  31. private void OnApplicationQuit()
  32. {
  33. SQLiteHelper.Instance.CloseConnection(true);
  34. }
  35. private void CheckExitAlert()
  36. {
  37. if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.Home))
  38. {
  39. QDManager.Exit();
  40. }
  41. }
  42. private float pauseTime;
  43. private void OnApplicationPause(bool pause)
  44. {
  45. if(pause)
  46. {
  47. pauseTime = Time.realtimeSinceStartup;
  48. }
  49. else
  50. {
  51. if(Time.realtimeSinceStartup - pauseTime > 300 || LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL)
  52. {
  53. StartCoroutine(CheckVersion(VersionController.DefaultPackage));
  54. }
  55. }
  56. }
  57. private IEnumerator CheckVersion(string packageName)
  58. {
  59. var package = YooAssets.GetPackage(packageName);
  60. string oldVersion = package.GetPackageVersion();
  61. var operation = package.UpdatePackageVersionAsync();
  62. yield return operation;
  63. if (operation.Status == EOperationStatus.Succeed)
  64. {
  65. VersionController.Instance.PackageVersion = operation.PackageVersion;
  66. LogUtil.LogDev($"版本对比: {oldVersion} {operation.PackageVersion}");
  67. if(!operation.PackageVersion.Equals(oldVersion))
  68. {
  69. AlertSystem.Show("游戏已有更新,您可以立即重启游戏获取最佳游戏体验,也可以稍后重启更新。")
  70. .SetLeftButton(true, "稍后更新")
  71. .SetRightButton(true, "重启游戏", (obj)=>
  72. {
  73. Application.Quit();
  74. });
  75. }
  76. }
  77. }
  78. }
  79. }