LauncherController.cs 5.0 KB

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