From cb2b633dc21c5ada5feda2fad3d20e402b3801be Mon Sep 17 00:00:00 2001 From: Michael Werle Date: Wed, 17 May 2017 18:25:41 +0100 Subject: [PATCH 1/4] Fix auto-loading the VAB or SPH --- DevHelper/DevHelper.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/DevHelper/DevHelper.cs b/DevHelper/DevHelper.cs index 7e48cdd..3240903 100644 --- a/DevHelper/DevHelper.cs +++ b/DevHelper/DevHelper.cs @@ -91,9 +91,11 @@ private void Update() { case "VAB": HighLogic.CurrentGame.startScene = GameScenes.EDITOR; + HighLogic.CurrentGame.editorFacility = EditorFacility.VAB; break; case "SPH": - HighLogic.CurrentGame.startScene = GameScenes.SPH; + HighLogic.CurrentGame.startScene = GameScenes.EDITOR; + HighLogic.CurrentGame.editorFacility = EditorFacility.SPH; break; case "Tracking Station": HighLogic.CurrentGame.startScene = GameScenes.TRACKSTATION; @@ -127,7 +129,7 @@ internal void DHButtons() DHReloadDatabase = ToolbarManager.Instance.add("DevHelper", "DHReloadGD"); DHReloadDatabase.TexturePath = "DevHelper/Textures/icon_buttonReload"; DHReloadDatabase.ToolTip = "Reload Game Database"; - DHReloadDatabase.Visibility = new GameScenesVisibility(GameScenes.EDITOR, GameScenes.SPH, GameScenes.SPACECENTER); + DHReloadDatabase.Visibility = new GameScenesVisibility(GameScenes.EDITOR); DHReloadDatabase.OnClick += (e) => { GameDatabase.Instance.Recompile = true; From d55f9e58ea20d97d026d3fc63204e496b7b82150 Mon Sep 17 00:00:00 2001 From: Michael Werle Date: Wed, 17 May 2017 18:26:18 +0100 Subject: [PATCH 2/4] Add "Flight" scene to autoload options --- DevHelper/DevHelper.cs | 3 +++ DevHelper/GUI.cs | 13 ++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/DevHelper/DevHelper.cs b/DevHelper/DevHelper.cs index 3240903..acf1b6e 100644 --- a/DevHelper/DevHelper.cs +++ b/DevHelper/DevHelper.cs @@ -103,6 +103,9 @@ private void Update() case "Space Center": HighLogic.CurrentGame.startScene = GameScenes.SPACECENTER; break; + case "Flight": + HighLogic.CurrentGame.startScene = GameScenes.FLIGHT; + break; default: HighLogic.CurrentGame.startScene = GameScenes.SPACECENTER; break; diff --git a/DevHelper/GUI.cs b/DevHelper/GUI.cs index b970835..10040c4 100644 --- a/DevHelper/GUI.cs +++ b/DevHelper/GUI.cs @@ -39,11 +39,14 @@ private void InitComboBox() private void InitComboBoxScenes() { - comboBoxSelectedList = new GUIContent[4]; - comboBoxSelectedList[0] = new GUIContent("VAB"); - comboBoxSelectedList[1] = new GUIContent("SPH"); - comboBoxSelectedList[2] = new GUIContent("Tracking Station"); - comboBoxSelectedList[3] = new GUIContent("Space Center"); + comboBoxSelectedList = new GUIContent[] + { + new GUIContent("VAB"), + new GUIContent("SPH"), + new GUIContent("Tracking Station"), + new GUIContent("Space Center"), + new GUIContent("Flight"), + }; comboBoxControlSpecificScene.SelectedItemIndex = comboBoxSelectedList.ToList().FindIndex(x => x.text == autoLoadSceneName); //Debug.Log("scene index: " + comboBoxControlSpecificScene.SelectedItemIndex); listStyle.normal.textColor = Color.white; From 7117cd0d8034ab70f557d9cdb66dcee3b11c39c1 Mon Sep 17 00:00:00 2001 From: Michael Werle Date: Tue, 21 Nov 2017 18:37:14 +0000 Subject: [PATCH 3/4] Replace print with Debug.log --- DevHelper/DevHelper.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/DevHelper/DevHelper.cs b/DevHelper/DevHelper.cs index acf1b6e..fb90d97 100644 --- a/DevHelper/DevHelper.cs +++ b/DevHelper/DevHelper.cs @@ -18,10 +18,15 @@ public partial class DevHelper : MonoBehaviour public bool autoLoadScene = true; public string autoLoadSceneName = "VAB"; + private void log(string msg) + { + Debug.Log("[DevHelper] " + msg); + } + private List saveNames; private void FindSaves() { - print("FindSaves"); + log("FindSaves"); var dirs = Directory.GetDirectories(KSPUtil.ApplicationRootPath + "saves\\"); saveNames = dirs.Where(x => System.IO.File.Exists(x + "\\persistent.sfs")).Select(x => x.Split(new[] { '\\' })[1]).ToList(); } @@ -29,17 +34,18 @@ private void FindSaves() //IButton DHReloadDatabase; private void Awake() { - print("Injector awake"); + log("Injector awake"); DontDestroyOnLoad(this); } + private void Start() { - print("DevHelper Starting"); + log("DevHelper Starting"); if (ToolbarManager.ToolbarAvailable) { DHButtons(); - Debug.Log("buttons loaded"); + log("buttons loaded"); } loadConfigXML(); From cd647e4465063e023795a460c769d60f9485e02c Mon Sep 17 00:00:00 2001 From: Michael Werle Date: Tue, 21 Nov 2017 18:41:50 +0000 Subject: [PATCH 4/4] Replace the deprecated OnLevelWasLoaded callback with a SceneManager.sceneLoaded delegate. --- DevHelper/DevHelper.cs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/DevHelper/DevHelper.cs b/DevHelper/DevHelper.cs index fb90d97..64ca776 100644 --- a/DevHelper/DevHelper.cs +++ b/DevHelper/DevHelper.cs @@ -1,9 +1,8 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using System.Linq; -using System.Xml.Serialization; using UnityEngine; +using UnityEngine.SceneManagement; using KSP.IO; //using MuMech; @@ -38,6 +37,12 @@ private void Awake() DontDestroyOnLoad(this); } + void OnEnable() + { + log("Injector enabled"); + SceneManager.sceneLoaded += OnSceneLoaded; + } + private void Start() { log("DevHelper Starting"); @@ -155,18 +160,17 @@ void OnDestroy() DHReloadDatabase.Destroy(); } } - - - private bool isTooLateToLoad = false; - - public void OnLevelWasLoaded(int level) + private bool isTooLateToLoad = false; + void OnSceneLoaded(Scene scene, LoadSceneMode mode) { - print("OnLevelWasLoaded:" + level); - + log("OnSceneLoaded for Scene " + scene.name); if (PSystemManager.Instance != null && ScaledSpace.Instance == null) { isTooLateToLoad = true; + log("It's now too late to load"); + // we no longer need this callback + SceneManager.sceneLoaded -= OnSceneLoaded; } } }