LauncherController.cs 4.2 KB

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