LauncherController.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. Alert.Show("游戏正在维护中,请稍后再试。")
  42. .SetLeftButton(true, "知道了", (data) =>
  43. {
  44. Application.Quit();
  45. });
  46. }
  47. else
  48. {
  49. #if UNITY_EDITOR
  50. InitResVersion();
  51. #else
  52. CheckApkVersion();
  53. #endif
  54. }
  55. }
  56. private static void CheckApkVersion()
  57. {
  58. var versionTarget = LauncherConfig.apkVersion;
  59. var version = Application.version;
  60. if (VersionUtil.compare(version, versionTarget))
  61. {
  62. DownloadApk();
  63. }
  64. else
  65. {
  66. InitResVersion();
  67. }
  68. }
  69. private static void DownloadApk()
  70. {
  71. Alert.Show("需要安装新的安装包,请联系研发获取。")
  72. .SetLeftButton(true, "知道了", (data) =>
  73. {
  74. Application.Quit();
  75. });
  76. }
  77. private static void InitResVersion()
  78. {
  79. VersionController.Instance.Init();
  80. }
  81. public static void OnVersionCompleted()
  82. {
  83. StartGame();
  84. }
  85. private static void StartGame()
  86. {
  87. LauncherView.Instance.SetDesc($"正在初始化...");
  88. HotUpdateCodeLoader.Instance.StartLoad();
  89. }
  90. private static void InitReporter()
  91. {
  92. Reporter reporter = GameObject.Find("Reporter").GetComponent<Reporter>();
  93. reporter.numOfCircleToShow = 10;
  94. reporter.isOpen = LauncherConfig.onDebug > 0;
  95. }
  96. private static void InitBugly()
  97. {
  98. BuglyAgent.ConfigDebugMode(true);
  99. // 注册日志回调,替换使用 'Application.RegisterLogCallback(Application.LogCallback)'注册日志回调的方式
  100. // BuglyAgent.RegisterLogCallback (CallbackDelegate.Instance.OnApplicationLogCallbackHandler);
  101. #if UNITY_IPHONE || UNITY_IOS
  102. BuglyAgent.InitWithAppId (BuglyAppIDForiOS);
  103. #elif UNITY_ANDROID
  104. if (LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL)
  105. {
  106. BuglyAgent.InitWithAppId("766c5bdb0f");
  107. }
  108. else if (LauncherConfig.netType == LauncherConfig.EnumNetType.TEMP)
  109. {
  110. BuglyAgent.InitWithAppId("b6d0b1b8c5");
  111. }
  112. #endif
  113. // 如果你确认已在对应的iOS工程或Android工程中初始化SDK,那么在脚本中只需启动C#异常捕获上报功能即可
  114. BuglyAgent.EnableExceptionHandler();
  115. }
  116. }
  117. }