HotUpdateDriver.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. Reporter reporter = GameObject.Find("Reporter").GetComponent<Reporter>();
  22. if(LauncherConfig.ChannelId != (int)ChannelID.Test && reporter != null)
  23. {
  24. reporter.numOfCircleToShow = 50;
  25. }
  26. }
  27. private void Update()
  28. {
  29. OperationSystem.Update();
  30. CheckExitAlert();
  31. }
  32. private void OnDestroy()
  33. {
  34. OperationSystem.DestroyAll();
  35. }
  36. private void OnApplicationQuit()
  37. {
  38. SQLiteHelper.Instance.CloseConnection(true);
  39. }
  40. private void CheckExitAlert()
  41. {
  42. if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.Home))
  43. {
  44. QDManager.Exit();
  45. }
  46. }
  47. private long pauseTime;
  48. private void OnApplicationPause(bool pause)
  49. {
  50. if(pause)
  51. {
  52. pauseTime = ET.TimeHelper.ClientNowSeconds();
  53. }
  54. else
  55. {
  56. if(ET.TimeHelper.ClientNowSeconds() - pauseTime > 180 || LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL)
  57. {
  58. StartCoroutine(CheckVersion(VersionController.DefaultPackage));
  59. }
  60. }
  61. }
  62. private IEnumerator CheckVersion(string packageName)
  63. {
  64. var package = YooAssets.GetPackage(packageName);
  65. string oldVersion = package.GetPackageVersion();
  66. var operation = package.UpdatePackageVersionAsync();
  67. yield return operation;
  68. if (operation.Status == EOperationStatus.Succeed)
  69. {
  70. VersionController.Instance.PackageVersion = operation.PackageVersion;
  71. LogUtil.LogDev($"版本对比: {oldVersion} {operation.PackageVersion}");
  72. if(!operation.PackageVersion.Equals(oldVersion))
  73. {
  74. AlertSystem.Show("游戏已有更新,您可以立即重启游戏获取最佳游戏体验,也可以稍后重启更新。")
  75. .SetLeftButton(true, "稍后更新")
  76. .SetRightButton(true, "重启游戏", (obj)=>
  77. {
  78. Application.Quit();
  79. });
  80. }
  81. }
  82. }
  83. }
  84. }