GameLauncher.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using UnityEngine;
  2. using GFGGame;
  3. using GFGGame.Launcher;
  4. using FairyGUI;
  5. using System;
  6. using System.Collections.Generic;
  7. public class GameLauncher : MonoBehaviour
  8. {
  9. private void Awake()
  10. {
  11. DontDestroyOnLoad(gameObject);
  12. }
  13. // Start is called before the first frame update
  14. void Start()
  15. {
  16. Screen.sleepTimeout = SleepTimeout.NeverSleep;
  17. Application.runInBackground = true;
  18. LauncherConfig.InitScriptCompilation();
  19. FGUILauncher.Init();
  20. HealthAdviceView.Instance.Open();
  21. InitBugly();
  22. int time = LauncherConfig.netType == LauncherConfig.EnumNetType.TISHEN ? 10 : 1;
  23. Timers.inst.Add(time, 1, (object param) =>
  24. {
  25. HealthAdviceView.Instance.Close();
  26. LauncherView.Instance.Open();
  27. InitLauncherCfg();
  28. });
  29. }
  30. /// <summary>
  31. /// 初始化启动器配置
  32. /// </summary>
  33. public void InitLauncherCfg()
  34. {
  35. LauncherView.Instance.SetDesc("正在初始化..");
  36. var url = LauncherConfig.cfgUrl.Replace("{cfgName}", LauncherConfig.cfgName);
  37. url = url + "?t=" + DateTime.Now.Ticks;
  38. HttpTool.Instance.Get(url, (string json) =>
  39. {
  40. LauncherConfig.InitPlatform(json);
  41. LauncherView.Instance.SetDesc("正在初始化...");
  42. //第一个节点必须放在平台配置加载之后
  43. LogServerHelperHttp.SendNodeLog((int)LogNode.OnStart);
  44. CheckGameStatus();
  45. });
  46. }
  47. public void CheckGameStatus()
  48. {
  49. if (LauncherConfig.serverStatus == 1)
  50. {
  51. Alert.Show("游戏正在维护中,请稍后再试。")
  52. .SetLeftButton(true, "知道了", (data) =>
  53. {
  54. Application.Quit();
  55. });
  56. }
  57. else
  58. {
  59. #if UNITY_EDITOR
  60. VersionController.Instance.Init();
  61. #else
  62. CheckApkVersion();
  63. #endif
  64. }
  65. }
  66. private void CheckApkVersion()
  67. {
  68. LauncherView.Instance.SetDesc("正在校验应用版本...");
  69. var versionTarget = LauncherConfig.apkVersion;
  70. var version = Application.version;
  71. if (VersionUtil.compare(version, versionTarget))
  72. {
  73. DownloadApk();
  74. }
  75. else
  76. {
  77. VersionController.Instance.Init();
  78. }
  79. }
  80. private void DownloadApk()
  81. {
  82. Alert.Show("需要安装新的安装包,请联系研发获取。")
  83. .SetLeftButton(true, "知道了", (data) =>
  84. {
  85. Application.Quit();
  86. });
  87. }
  88. private void InitBugly()
  89. {
  90. BuglyAgent.ConfigDebugMode(true);
  91. // 注册日志回调,替换使用 'Application.RegisterLogCallback(Application.LogCallback)'注册日志回调的方式
  92. // BuglyAgent.RegisterLogCallback (CallbackDelegate.Instance.OnApplicationLogCallbackHandler);
  93. #if UNITY_IPHONE || UNITY_IOS
  94. BuglyAgent.InitWithAppId (BuglyAppIDForiOS);
  95. #elif UNITY_ANDROID
  96. if (LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL)
  97. {
  98. BuglyAgent.InitWithAppId("766c5bdb0f");
  99. }
  100. else if (LauncherConfig.netType == LauncherConfig.EnumNetType.TEMP)
  101. {
  102. BuglyAgent.InitWithAppId("b6d0b1b8c5");
  103. }
  104. #endif
  105. // 如果你确认已在对应的iOS工程或Android工程中初始化SDK,那么在脚本中只需启动C#异常捕获上报功能即可
  106. BuglyAgent.EnableExceptionHandler();
  107. }
  108. }