コード例 #1
0
        /// <summary>
        /// Called whenever a scene change occurs. Ensures the server has been initialized,
        /// (re)creates the UI, and shuts down the server in the main menu.
        /// </summary>
        public void Awake()
        {
            if (!ServicesChecker.OK)
            {
                return;
            }

            Init();
            Instance = this;

            Service.CallContext.SetGameScene(HighLogic.LoadedScene.ToGameScene());
            Utils.Logger.WriteLine("Game scene switched to " + Service.CallContext.GameScene);

            // If a game is not loaded, ensure the server is stopped and then exit
            if (HighLogic.LoadedScene != GameScenes.EDITOR &&
                HighLogic.LoadedScene != GameScenes.FLIGHT &&
                HighLogic.LoadedScene != GameScenes.SPACECENTER &&
                HighLogic.LoadedScene != GameScenes.TRACKSTATION)
            {
                core.StopAll();
                return;
            }

            // Auto-start the server, if required
            if (config.Configuration.AutoStartServers)
            {
                Utils.Logger.WriteLine("Auto-starting server");
                try {
                    core.StartAll();
                } catch (ServerException e) {
                    Utils.Logger.WriteLine("Failed to auto-start servers:" + e, Utils.Logger.Severity.Error);
                }
            }

            // (Re)create the UI
            InitUI();
        }
コード例 #2
0
        /// <summary>
        /// Called whenever a scene change occurs. Ensures the server has been initialized,
        /// (re)creates the UI, and shuts down the server in the main menu.
        /// </summary>
        public void Awake()
        {
            if (!ServicesChecker.OK)
            {
                return;
            }

            Init();
            Instance = this;

            var gameScene = GameScenesExtensions.CurrentGameScene();

            Service.CallContext.SetGameScene(gameScene);
            Utils.Logger.WriteLine("Game scene switched to " + gameScene);

            // If a game is not loaded, ensure the server is stopped and then exit
            if (gameScene == Service.GameScene.None)
            {
                core.StopAll();
                return;
            }

            // Auto-start the server, if required
            if (config.Configuration.AutoStartServers)
            {
                Utils.Logger.WriteLine("Auto-starting server");
                try {
                    core.StartAll();
                } catch (ServerException e) {
                    Utils.Logger.WriteLine("Failed to auto-start servers:" + e, Utils.Logger.Severity.Error);
                }
            }

            // (Re)create the UI
            InitUI();
        }