LauncherController.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. // CheckGameStatus();
  23. //});
  24. InitSDK();
  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. 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. HotUpdateCodeLoader.Instance.StartLoad();
  116. }
  117. private static void InitReporter()
  118. {
  119. Reporter reporter = GameObject.Find("Reporter").GetComponent<Reporter>();
  120. reporter.numOfCircleToShow = 10;
  121. reporter.isOpen = LauncherConfig.onDebug > 0;
  122. }
  123. private static void InitBugly()
  124. {
  125. //BuglyAgent.ConfigDebugMode(true);
  126. // 注册日志回调,替换使用 'Application.RegisterLogCallback(Application.LogCallback)'注册日志回调的方式
  127. // BuglyAgent.RegisterLogCallback (CallbackDelegate.Instance.OnApplicationLogCallbackHandler);
  128. #if UNITY_IPHONE || UNITY_IOS
  129. BuglyAgent.InitWithAppId ("f8cf2b57f3");
  130. #elif UNITY_ANDROID
  131. if (LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL)
  132. {
  133. BuglyAgent.InitWithAppId("766c5bdb0f");
  134. }
  135. else if (LauncherConfig.netType == LauncherConfig.EnumNetType.PUBLIC)
  136. {
  137. BuglyAgent.InitWithAppId("b6d0b1b8c5");
  138. }
  139. #endif
  140. // 如果你确认已在对应的iOS工程或Android工程中初始化SDK,那么在脚本中只需启动C#异常捕获上报功能即可
  141. // BuglyAgent.EnableExceptionHandler();
  142. }
  143. }
  144. }