using UnityEngine; using GFGGame; using GFGGame.Launcher; using FairyGUI; using System; using System.Collections.Generic; public class GameLauncher : MonoBehaviour { private void Awake() { DontDestroyOnLoad(gameObject); } // Start is called before the first frame update void Start() { Screen.sleepTimeout = SleepTimeout.NeverSleep; Application.runInBackground = true; LauncherConfig.InitScriptCompilation(); FGUILauncher.Init(); HealthAdviceView.Instance.Open(); InitBugly(); int time = LauncherConfig.netType == LauncherConfig.EnumNetType.TISHEN ? 10 : 1; Timers.inst.Add(time, 1, (object param) => { HealthAdviceView.Instance.Close(); LauncherView.Instance.Open(); InitLauncherCfg(); }); } /// /// 初始化启动器配置 /// public void InitLauncherCfg() { LauncherView.Instance.SetDesc("正在初始化.."); var url = LauncherConfig.cfgUrl.Replace("{cfgName}", LauncherConfig.cfgName); url = url + "?t=" + DateTime.Now.Ticks; HttpTool.Instance.Get(url, (string json) => { LauncherConfig.InitPlatform(json); LauncherView.Instance.SetDesc("正在初始化..."); //第一个节点必须放在平台配置加载之后 LogServerHelperHttp.SendNodeLog((int)LogNode.OnStart); CheckGameStatus(); }); } public void CheckGameStatus() { if (LauncherConfig.serverStatus == 1) { Alert.Show("游戏正在维护中,请稍后再试。") .SetLeftButton(true, "知道了", (data) => { Application.Quit(); }); } else { #if UNITY_EDITOR VersionController.Instance.Init(); #else CheckApkVersion(); #endif } } private void CheckApkVersion() { LauncherView.Instance.SetDesc("正在校验应用版本..."); var versionTarget = LauncherConfig.apkVersion; var version = Application.version; if (VersionUtil.compare(version, versionTarget)) { DownloadApk(); } else { VersionController.Instance.Init(); } } private void DownloadApk() { Alert.Show("需要安装新的安装包,请联系研发获取。") .SetLeftButton(true, "知道了", (data) => { Application.Quit(); }); } private void InitBugly() { BuglyAgent.ConfigDebugMode(true); // 注册日志回调,替换使用 'Application.RegisterLogCallback(Application.LogCallback)'注册日志回调的方式 // BuglyAgent.RegisterLogCallback (CallbackDelegate.Instance.OnApplicationLogCallbackHandler); #if UNITY_IPHONE || UNITY_IOS BuglyAgent.InitWithAppId (BuglyAppIDForiOS); #elif UNITY_ANDROID if (LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL) { BuglyAgent.InitWithAppId("766c5bdb0f"); } else if (LauncherConfig.netType == LauncherConfig.EnumNetType.TEMP) { BuglyAgent.InitWithAppId("b6d0b1b8c5"); } #endif // 如果你确认已在对应的iOS工程或Android工程中初始化SDK,那么在脚本中只需启动C#异常捕获上报功能即可 BuglyAgent.EnableExceptionHandler(); } }