LauncherController.cs 4.9 KB

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