From e452f9d794cdead5dc0f4e27e86cedbe283df626 Mon Sep 17 00:00:00 2001 From: Stepan Andreev Date: Sun, 30 Oct 2016 10:28:37 +0000 Subject: [PATCH 1/2] Minor bugfix --- IRSequencer/IRSequencer/Gui/SequencerGUI.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/IRSequencer/IRSequencer/Gui/SequencerGUI.cs b/IRSequencer/IRSequencer/Gui/SequencerGUI.cs index bfe5c1c..0f6e882 100644 --- a/IRSequencer/IRSequencer/Gui/SequencerGUI.cs +++ b/IRSequencer/IRSequencer/Gui/SequencerGUI.cs @@ -1934,16 +1934,25 @@ private void CloseAllWindows() _controlWindowFader = null; }); - if (_settingsWindow) + if (_settingsWindowFader) { - SequencerSettingsWindowPosition = _settingsWindow.transform.position; - _settingsWindowFader.FadeTo(0f, 0.1f, () => { + if (_settingsWindow.activeSelf) + _settingsWindowFader.FadeTo(0f, 0.1f, () => + { + SequencerSettingsWindowPosition = _settingsWindow.transform.position; + _settingsWindow.DestroyGameObjectImmediate(); + _settingsWindow = null; + _settingsWindowFader = null; + }); + else + { + SequencerSettingsWindowPosition = _settingsWindow.transform.position; _settingsWindow.DestroyGameObjectImmediate(); _settingsWindow = null; _settingsWindowFader = null; - }); - + } } + EditorLocker.EditorLock(false); } From 092ccd37b19d68e619c7559bbf79e22e358ac184 Mon Sep 17 00:00:00 2001 From: Stepan Andreev Date: Sun, 30 Oct 2016 10:34:46 +0000 Subject: [PATCH 2/2] Redid the hooking into main IR asset bundle --- IRSequencer/IRSequencer/Gui/UIAssetsLoader.cs | 78 ++++++++++++------- 1 file changed, 48 insertions(+), 30 deletions(-) diff --git a/IRSequencer/IRSequencer/Gui/UIAssetsLoader.cs b/IRSequencer/IRSequencer/Gui/UIAssetsLoader.cs index 0afb8fc..ac4e2b9 100644 --- a/IRSequencer/IRSequencer/Gui/UIAssetsLoader.cs +++ b/IRSequencer/IRSequencer/Gui/UIAssetsLoader.cs @@ -8,7 +8,7 @@ namespace IRSequencer.Gui { - [KSPAddon(KSPAddon.Startup.SpaceCentre, true)] + [KSPAddon(KSPAddon.Startup.MainMenu, false)] public class UIAssetsLoader : MonoBehaviour { private AssetBundle IRAssetBundle; @@ -30,21 +30,6 @@ public class UIAssetsLoader : MonoBehaviour public static bool allPrefabsReady = false; - public IEnumerator LoadBundle(string location) - { - while (!Caching.ready) - yield return null; - using (WWW www = WWW.LoadFromCacheOrDownload(location, 1)) - { - yield return www; - IRAssetBundle = www.assetBundle; - - LoadBundleAssets(); - - //IRAssetBundle.Unload(false); - } - } - private void LoadBundleAssets() { var prefabs = IRAssetBundle.LoadAllAssets(); @@ -131,18 +116,12 @@ private void LoadBundleAssets() public void Start() { - var assemblyFile = Assembly.GetExecutingAssembly().Location; - - var bundlePath = "file://" + assemblyFile.Replace(new FileInfo(assemblyFile).Name, "").Replace("\\","/") + "../../AssetBundles/"; - - Logger.Log("Loading bundles from BundlePath: " + bundlePath, Logger.Level.Debug); - + if (allPrefabsReady) + return; //there is no need to reload the prefabs or any other assets. + //need to clean cache Caching.CleanCache(); - - if(!allPrefabsReady) - StartCoroutine(LoadBundle(bundlePath + "ir_ui_objects.ksp")); - + Type IRAssetsLoaderType = null; AssemblyLoader.loadedAssemblies.TypeOperation (t => { @@ -151,23 +130,62 @@ public void Start() } }); - var fieldInfo = IRAssetsLoaderType.GetField("iconAssets", BindingFlags.NonPublic | BindingFlags.Static); + var fieldInfo = IRAssetsLoaderType.GetField("IRAssetBundle", BindingFlags.NonPublic | BindingFlags.Static); + IRAssetBundle = (AssetBundle)fieldInfo.GetValue(null); + if (!allPrefabsReady) + { + if (IRAssetBundle != null) + { + LoadBundleAssets(); + } + } + + fieldInfo = IRAssetsLoaderType.GetField("iconAssets", BindingFlags.NonPublic | BindingFlags.Static); iconAssets = (List)fieldInfo.GetValue(null); fieldInfo = IRAssetsLoaderType.GetField("spriteAssets", BindingFlags.NonPublic | BindingFlags.Static); - spriteAssets = (List)fieldInfo.GetValue(null); } + public void Update() + { + if(!allPrefabsReady) + { + Type IRAssetsLoaderType = null; + + AssemblyLoader.loadedAssemblies.TypeOperation(t => + { + if (t.FullName == "InfernalRobotics.Gui.UIAssetsLoader") + { + IRAssetsLoaderType = t; + } + }); + + var fieldInfo = IRAssetsLoaderType.GetField("IRAssetBundle", BindingFlags.NonPublic | BindingFlags.Static); + IRAssetBundle = (AssetBundle)fieldInfo.GetValue(null); + + if (IRAssetBundle != null) + { + LoadBundleAssets(); + } + + fieldInfo = IRAssetsLoaderType.GetField("iconAssets", BindingFlags.NonPublic | BindingFlags.Static); + iconAssets = (List)fieldInfo.GetValue(null); + + fieldInfo = IRAssetsLoaderType.GetField("spriteAssets", BindingFlags.NonPublic | BindingFlags.Static); + spriteAssets = (List)fieldInfo.GetValue(null); + } + } + public void OnDestroy() { - if(IRAssetBundle) + /*if(IRAssetBundle) { Logger.Log("Unloading bundle", Logger.Level.Debug); IRAssetBundle.Unload(false); - } + }*/ } } }