GameLauncher.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using UnityEngine;
  2. using GFGGame;
  3. using ET;
  4. using System.Threading;
  5. using GFGGame.Launcher;
  6. public class GameLauncher : MonoBehaviour
  7. {
  8. private void Awake()
  9. {
  10. //ET
  11. System.AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
  12. {
  13. Log.Error(e.ExceptionObject.ToString());
  14. };
  15. SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);
  16. DontDestroyOnLoad(gameObject);
  17. ETTask.ExceptionHandler += Log.Error;
  18. Log.ILog = new UnityLogger();
  19. Options.Instance = new Options();
  20. TimeInfo.Instance.TimeZone = 8;
  21. }
  22. // Start is called before the first frame update
  23. void Start()
  24. {
  25. Screen.sleepTimeout = SleepTimeout.NeverSleep;
  26. Application.runInBackground = true;
  27. LauncherConfig.InitScriptCompilation();
  28. FGUILauncher.Init();
  29. LauncherView.Instance.Open();
  30. InitLauncherCfg();
  31. }
  32. /// <summary>
  33. /// 初始化启动器配置
  34. /// </summary>
  35. public void InitLauncherCfg()
  36. {
  37. LauncherView.Instance.SetDesc("正在初始化..");
  38. var url = LauncherConfig.cfgUrl.Replace("{cfgName}", LauncherConfig.cfgName);
  39. HttpTool.Instance.Get(url, (string json) =>
  40. {
  41. LauncherConfig.InitPlatform(json);
  42. LauncherView.Instance.SetDesc("正在初始化...");
  43. //第一个节点必须放在平台配置加载之后
  44. LogServerHelperHttp.SendNodeLog((int)LogNode.OnStart);
  45. CheckGameStatus();
  46. });
  47. }
  48. public void CheckGameStatus()
  49. {
  50. if(LauncherConfig.serverStatus == 1)
  51. {
  52. Alert.Show("游戏正在维护中,请稍后再试。")
  53. .SetLeftButton(true, "知道了", (data) => {
  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. Application.Quit();
  81. });
  82. }
  83. }