GameLauncher.cs 3.4 KB

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