HotUpdateDriver.cs 2.9 KB

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