HotUpdateDriver.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 void OnApplicationPause(bool pause)
  43. {
  44. if(!pause)
  45. {
  46. StartCoroutine(CheckVersion(VersionController.DefaultPackage));
  47. }
  48. }
  49. private IEnumerator CheckVersion(string packageName)
  50. {
  51. var package = YooAssets.GetPackage(packageName);
  52. string oldVersion = package.GetPackageVersion();
  53. var operation = package.UpdatePackageVersionAsync();
  54. yield return operation;
  55. if (operation.Status == EOperationStatus.Succeed)
  56. {
  57. VersionController.Instance.PackageVersion = operation.PackageVersion;
  58. LogUtil.LogDev($"版本对比: {oldVersion} {operation.PackageVersion}");
  59. if(!operation.PackageVersion.Equals(oldVersion))
  60. {
  61. AlertSystem.Show("游戏已有更新,您可以立即重启游戏获取最佳游戏体验,也可以稍后重启更新。")
  62. .SetLeftButton(true, "稍后更新")
  63. .SetRightButton(true, "重启游戏", (obj)=>
  64. {
  65. Application.Quit();
  66. });
  67. }
  68. }
  69. }
  70. }
  71. }