GameLauncher.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. CheckApkVersion();
  60. }
  61. }
  62. private void CheckApkVersion()
  63. {
  64. LauncherView.Instance.SetDesc("正在校验应用版本...");
  65. var versionTarget = LauncherConfig.apkVersion;
  66. var version = Application.version;
  67. if (VersionUtil.compare(version, versionTarget))
  68. {
  69. DownloadApk();
  70. }
  71. else
  72. {
  73. VersionController.Instance.Init();
  74. }
  75. }
  76. private void DownloadApk()
  77. {
  78. Alert.Show("需要安装新的安装包,请联系研发获取。")
  79. .SetLeftButton(true, "知道了", (data) =>
  80. {
  81. Application.Quit();
  82. });
  83. }
  84. private void InitBugly()
  85. {
  86. BuglyAgent.ConfigDebugMode(true);
  87. // 注册日志回调,替换使用 'Application.RegisterLogCallback(Application.LogCallback)'注册日志回调的方式
  88. // BuglyAgent.RegisterLogCallback (CallbackDelegate.Instance.OnApplicationLogCallbackHandler);
  89. #if UNITY_IPHONE || UNITY_IOS
  90. BuglyAgent.InitWithAppId (BuglyAppIDForiOS);
  91. #elif UNITY_ANDROID
  92. if (LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL)
  93. {
  94. BuglyAgent.InitWithAppId("766c5bdb0f");
  95. }
  96. else if (LauncherConfig.netType == LauncherConfig.EnumNetType.TEMP)
  97. {
  98. BuglyAgent.InitWithAppId("b6d0b1b8c5");
  99. }
  100. #endif
  101. // 如果你确认已在对应的iOS工程或Android工程中初始化SDK,那么在脚本中只需启动C#异常捕获上报功能即可
  102. BuglyAgent.EnableExceptionHandler();
  103. }
  104. }