LauncherController.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. using System;
  2. using GFGGame.Launcher;
  3. using UnityEngine;
  4. using UniFramework.Event;
  5. namespace GFGGame
  6. {
  7. public class LauncherController
  8. {
  9. private static EventGroup eventGroup = new EventGroup();
  10. /// <summary>
  11. /// 初始化启动器配置
  12. /// </summary>
  13. public static void InitLauncherCfg()
  14. {
  15. LauncherView.Instance.SetDesc("正在检查更新...");
  16. Debug.Log($"正在检查更新...");
  17. var url = LauncherConfig.cfgUrl.Replace("{cfgName}", LauncherConfig.cfgName);
  18. url = url + "?t=" + DateTime.Now.Ticks;
  19. HttpTool.Instance.Get(url, (string json) =>
  20. {
  21. LauncherConfig.InitPlatform(json);
  22. //CheckShowAgreeView(CheckGameStatus);
  23. CheckGameStatus();
  24. Debug.Log($"正在检查更新...CheckGameStatus");
  25. });
  26. }
  27. private static void CheckShowAgreeView(Action onSuccess)
  28. {
  29. if (LocalCache.GetBool(LauncherConfig.LAST_LOGIN_IS_AGREE_KEY, false))
  30. {
  31. onSuccess?.Invoke();
  32. }
  33. else
  34. {
  35. LauncherAgreeView.Instance.Open(() => {
  36. onSuccess?.Invoke();
  37. });
  38. }
  39. }
  40. public static void CheckGameStatus()
  41. {
  42. if (LauncherConfig.serverStatus == 1)
  43. {
  44. if(string.IsNullOrEmpty(LauncherConfig.statusPrompt))
  45. {
  46. LauncherConfig.statusPrompt = "游戏正在维护中,请稍后再试。";
  47. }
  48. Alert.Show(LauncherConfig.statusPrompt)
  49. .SetLeftButton(true, "知道了", (data) =>
  50. {
  51. Application.Quit();
  52. });
  53. }
  54. else
  55. {
  56. InitSDK();
  57. }
  58. }
  59. private static void InitSDK()
  60. {
  61. InitReporter();
  62. Debug.Log($"InitSDK...InitReporter");
  63. //InitBugly();
  64. eventGroup.AddListener<LauncherEvent.InitPlatformResult>(OnInitPlatform);
  65. QDManagerInit.InitPlatform();
  66. }
  67. private static void OnInitPlatform(IEventMessage obj)
  68. {
  69. LauncherEvent.InitPlatformResult initPlatformResult = obj as LauncherEvent.InitPlatformResult;
  70. Debug.Log($"OnInitPlatform InitPlatformResult");
  71. if (initPlatformResult != null)
  72. {
  73. if(initPlatformResult.success)
  74. {
  75. OnInitSDKSuccess();
  76. Debug.Log($"调试100");
  77. }
  78. else
  79. {
  80. OnInitSDKFail();
  81. Debug.Log($"调试101");
  82. }
  83. }
  84. }
  85. private static void OnInitSDKFail()
  86. {
  87. Alert.Show("初始化平台sdk失败!")
  88. .SetRightButton(true, "重试", (t) => { QDManagerInit.InitPlatform(); });
  89. }
  90. private static void OnInitSDKSuccess()
  91. {
  92. #if UNITY_EDITOR
  93. InitResVersion();
  94. Debug.Log($"OnInitSDKSuccess");
  95. #else
  96. CheckApkVersion();
  97. #endif
  98. }
  99. private static void CheckApkVersion()
  100. {
  101. Debug.Log($"CheckApkVersion...apkVersion");
  102. var versionTarget = LauncherConfig.apkVersion;
  103. var version = Application.version;
  104. if (VersionUtil.compare(version, versionTarget))
  105. {
  106. Debug.Log($"CheckApkVersion...UpdateApp");
  107. QDManagerInit.UpdateApp();
  108. Debug.Log($"CheckApkVersion UpdateApp");
  109. }
  110. else
  111. {
  112. InitResVersion();
  113. Debug.Log($"CheckApkVersion InitResVersion");
  114. }
  115. }
  116. private static void InitResVersion()
  117. {
  118. VersionController.Instance.Init();
  119. Debug.Log($"调试InitResVersion");
  120. }
  121. public static void OnVersionCompleted()
  122. {
  123. StartGame();
  124. }
  125. private static void StartGame()
  126. {
  127. Debug.Log($"正在初始化0");
  128. LauncherView.Instance.SetDesc($"正在初始化...");
  129. Debug.Log($"正在初始化1");
  130. HotUpdateCodeLoader.Instance.StartLoad();
  131. }
  132. private static void InitReporter()
  133. {
  134. Reporter reporter = GameObject.Find("Reporter").GetComponent<Reporter>();
  135. reporter.numOfCircleToShow = 10;
  136. reporter.isOpen = LauncherConfig.onDebug > 0;
  137. }
  138. private static void InitBugly()
  139. {
  140. //BuglyAgent.ConfigDebugMode(true);
  141. // 注册日志回调,替换使用 'Application.RegisterLogCallback(Application.LogCallback)'注册日志回调的方式
  142. // BuglyAgent.RegisterLogCallback (CallbackDelegate.Instance.OnApplicationLogCallbackHandler);
  143. #if UNITY_IPHONE || UNITY_IOS
  144. BuglyAgent.InitWithAppId ("f8cf2b57f3");
  145. #elif UNITY_ANDROID
  146. if (LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL)
  147. {
  148. BuglyAgent.InitWithAppId("766c5bdb0f");
  149. }
  150. else if (LauncherConfig.netType == LauncherConfig.EnumNetType.PUBLIC)
  151. {
  152. BuglyAgent.InitWithAppId("b6d0b1b8c5");
  153. }
  154. #endif
  155. // 如果你确认已在对应的iOS工程或Android工程中初始化SDK,那么在脚本中只需启动C#异常捕获上报功能即可
  156. // BuglyAgent.EnableExceptionHandler();
  157. }
  158. }
  159. }