LauncherController.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. url = url + "?t=" + DateTime.Now.Ticks;
  18. HttpTool.Instance.Get(url, (string json) =>
  19. {
  20. LauncherConfig.InitPlatform(json);
  21. //CheckShowAgreeView(CheckGameStatus);
  22. 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. LauncherEvent.InitPlatformResult initPlatformResult = obj as LauncherEvent.InitPlatformResult;
  67. if (initPlatformResult != null)
  68. {
  69. if(initPlatformResult.success)
  70. {
  71. OnInitSDKSuccess();
  72. }
  73. else
  74. {
  75. OnInitSDKFail();
  76. }
  77. }
  78. }
  79. private static void OnInitSDKFail()
  80. {
  81. Alert.Show("初始化平台sdk失败!")
  82. .SetRightButton(true, "重试", (t) => { QDManagerInit.InitPlatform(); });
  83. }
  84. private static void OnInitSDKSuccess()
  85. {
  86. #if UNITY_EDITOR
  87. InitResVersion();
  88. #else
  89. CheckApkVersion();
  90. #endif
  91. }
  92. private static void CheckApkVersion()
  93. {
  94. var versionTarget = LauncherConfig.apkVersion;
  95. var version = Application.version;
  96. if (VersionUtil.compare(version, versionTarget))
  97. {
  98. QDManagerInit.UpdateApp();
  99. }
  100. else
  101. {
  102. InitResVersion();
  103. }
  104. }
  105. private static void InitResVersion()
  106. {
  107. VersionController.Instance.Init();
  108. }
  109. public static void OnVersionCompleted()
  110. {
  111. StartGame();
  112. }
  113. private static void StartGame()
  114. {
  115. LauncherView.Instance.SetDesc($"正在初始化...");
  116. HotUpdateCodeLoader.Instance.StartLoad();
  117. }
  118. private static void InitReporter()
  119. {
  120. Reporter reporter = GameObject.Find("Reporter").GetComponent<Reporter>();
  121. reporter.numOfCircleToShow = 10;
  122. reporter.isOpen = LauncherConfig.onDebug > 0;
  123. }
  124. private static void InitBugly()
  125. {
  126. BuglyAgent.ConfigDebugMode(true);
  127. // 注册日志回调,替换使用 'Application.RegisterLogCallback(Application.LogCallback)'注册日志回调的方式
  128. // BuglyAgent.RegisterLogCallback (CallbackDelegate.Instance.OnApplicationLogCallbackHandler);
  129. #if UNITY_IPHONE || UNITY_IOS
  130. BuglyAgent.InitWithAppId ("f8cf2b57f3");
  131. #elif UNITY_ANDROID
  132. if (LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL)
  133. {
  134. BuglyAgent.InitWithAppId("766c5bdb0f");
  135. }
  136. else if (LauncherConfig.netType == LauncherConfig.EnumNetType.PUBLIC)
  137. {
  138. BuglyAgent.InitWithAppId("b6d0b1b8c5");
  139. }
  140. #endif
  141. // 如果你确认已在对应的iOS工程或Android工程中初始化SDK,那么在脚本中只需启动C#异常捕获上报功能即可
  142. BuglyAgent.EnableExceptionHandler();
  143. }
  144. }
  145. }