GameLauncher.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using UnityEngine;
  2. using GFGGame;
  3. using ET;
  4. using System.Threading;
  5. using GFGGame.Launcher;
  6. using System;
  7. public class GameLauncher : MonoBehaviour
  8. {
  9. private void Awake()
  10. {
  11. //ET
  12. System.AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
  13. {
  14. Log.Error(e.ExceptionObject.ToString());
  15. };
  16. SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);
  17. DontDestroyOnLoad(gameObject);
  18. ETTask.ExceptionHandler += Log.Error;
  19. Log.ILog = new UnityLogger();
  20. Options.Instance = new Options();
  21. TimeInfo.Instance.TimeZone = 8;
  22. }
  23. // Start is called before the first frame update
  24. void Start()
  25. {
  26. Screen.sleepTimeout = SleepTimeout.NeverSleep;
  27. Application.runInBackground = true;
  28. LauncherConfig.InitScriptCompilation();
  29. FGUILauncher.Init();
  30. LauncherView.Instance.Open();
  31. InitLauncherCfg();
  32. }
  33. /// <summary>
  34. /// 初始化启动器配置
  35. /// </summary>
  36. public void InitLauncherCfg()
  37. {
  38. LauncherView.Instance.SetDesc("正在初始化..");
  39. var url = LauncherConfig.cfgUrl.Replace("{cfgName}", LauncherConfig.cfgName);
  40. url = url + "?t=" + TimeHelper.ClientNow();
  41. HttpTool.Instance.Get(url, (string json) =>
  42. {
  43. LauncherConfig.InitPlatform(json);
  44. LauncherView.Instance.SetDesc("正在初始化...");
  45. //第一个节点必须放在平台配置加载之后
  46. LogServerHelperHttp.SendNodeLog((int)LogNode.OnStart);
  47. CheckGameStatus();
  48. });
  49. }
  50. public void CheckGameStatus()
  51. {
  52. if(LauncherConfig.serverStatus == 1)
  53. {
  54. Alert.Show("游戏正在维护中,请稍后再试。")
  55. .SetLeftButton(true, "知道了", (data) => {
  56. Application.Quit();
  57. });
  58. }
  59. else
  60. {
  61. CheckApkVersion();
  62. }
  63. }
  64. private void CheckApkVersion()
  65. {
  66. LauncherView.Instance.SetDesc("正在校验应用版本...");
  67. var versionTarget = LauncherConfig.apkVersion;
  68. var version = Application.version;
  69. if (VersionUtil.compare(version, versionTarget))
  70. {
  71. DownloadApk();
  72. }
  73. else
  74. {
  75. VersionController.Instance.Init();
  76. }
  77. }
  78. private void DownloadApk()
  79. {
  80. Alert.Show("需要安装新的安装包,请联系研发获取。")
  81. .SetLeftButton(true, "知道了", (data) => {
  82. Application.Quit();
  83. });
  84. }
  85. }