LauncherController.cs 3.6 KB

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