From dc1b1ce2d030b19d2c9fdb7883959538b3447b56 Mon Sep 17 00:00:00 2001 From: Stepan Andreev Date: Thu, 21 Apr 2016 23:16:23 +0100 Subject: [PATCH 1/7] Still having bug in UIBundleLoader --- .gitignore | 1 + .../.vs/IRSequencer/IRSequencer.scgdat | Bin 131072 -> 131072 bytes IRSequencer/IRSequencer/Gui/UIAssetsLoader.cs | 14 ++++++++------ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 6a7520a..ccea93b 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,4 @@ IRSequencer/IRSequencer/obj/Release/IRSequencer.csproj.FileListAbsolute.txt IRSequencer/IRSequencer/obj/Release/IRSequencer.csproj.FilesWrittenAbsolute.txt *.cache +IRSequencer/.vs/IRSequencer/IRSequencer.scgdat diff --git a/IRSequencer/.vs/IRSequencer/IRSequencer.scgdat b/IRSequencer/.vs/IRSequencer/IRSequencer.scgdat index 7bbfc814a793a178e9bcbf5e2f2b215021398e09..15fd49a1c0d11199e3cfc28550908b732e928f58 100644 GIT binary patch delta 357 zcmZo@;Am*z;GDJ1X)*&4uubGtW)$71dzsNR1IT3oViAxq5Pt=7Du8q?NDv4>Y$qTF z$>~F}z{EgdrW?$Y`CAn?J1|Y<<$So~a}EcK0fWJ2P62&JMvlprg3g@mP+jbs4Vj)Z zZ*E!mf*GiK4V&aw2kHHsEC~#zKn2KveX`^RTTV6xM+Vmh1_t)cfeI7()ju#NFkfJD zVA{Z_z&HV@I>*CfodAmi!w#rU4xl^P7YI%lS77|4#tanv0kW47B->C>lwXiqRFaum z9FtgFoSK`IQ<<5UmcRMF!B#%iw-=b0P8l#UEoxw5Dm%c$ih}b2>17=NG8EE(0`G02~e=!zW*C(%P(WVITj-11XH#1rivS%mV<-w@6L!%}Y615*Ump$1atetfZj5+0kJ+ zzw!kp2c`{-3XBtgS`1cY^a-#yFl+;|L4X5j4(kG*$>Ij*H=7x* spriteAssets; public static bool allPrefabsReady = false; - + public IEnumerator LoadBundle(string location) { while (!Caching.ready) @@ -132,9 +132,9 @@ private void LoadBundleAssets() public void LoadBundleFromDisk(string path) { IRAssetBundle = AssetBundle.CreateFromFile(path); - + LoadBundleAssets(); - + //had to move bundle unloading further down in time due to unexplained and unreproducable on my PC issues for some users } @@ -153,9 +153,11 @@ public void Start() //StartCoroutine(LoadBundle(bundlePath + "ir_ui_objects.ksp")); Logger.Log("Loading bundles from filePath: " + filePath, Logger.Level.Debug); - LoadBundleFromDisk(filePath + "ir_ui_objects.ksp"); - } + if(!IRAssetBundle) + LoadBundleFromDisk(filePath + "ir_ui_objects.ksp"); + } + public void OnDestroy() { Logger.Log("Unloading bundle", Logger.Level.Debug); From 88abef7329cb0b409cf885c78c3befc9dba6b0ff Mon Sep 17 00:00:00 2001 From: ZiwKerman Date: Fri, 22 Apr 2016 09:08:02 +0100 Subject: [PATCH 2/7] Let's try AsyncLoading --- IRSequencer/IRSequencer/Gui/SequencerGUI.cs | 10 +- IRSequencer/IRSequencer/Gui/UIAssetsLoader.cs | 115 +++++++++++++++++- 2 files changed, 117 insertions(+), 8 deletions(-) diff --git a/IRSequencer/IRSequencer/Gui/SequencerGUI.cs b/IRSequencer/IRSequencer/Gui/SequencerGUI.cs index 44bc0cc..425c2aa 100644 --- a/IRSequencer/IRSequencer/Gui/SequencerGUI.cs +++ b/IRSequencer/IRSequencer/Gui/SequencerGUI.cs @@ -1759,13 +1759,19 @@ public void RebuildUI() else _sequenceUIControls.Clear(); - if (UIAssetsLoader.allPrefabsReady && _settingsWindow == null) + if (!UIAssetsLoader.allPrefabsReady) + { + GUIEnabled = false; + return; + } + + if (_settingsWindow == null) { InitSettingsWindow(); } //here we need to wait until prefabs become available and then Instatiate the window - if (UIAssetsLoader.allPrefabsReady && _controlWindow == null) + if (_controlWindow == null) { InitControlWindow(GUIEnabled); } diff --git a/IRSequencer/IRSequencer/Gui/UIAssetsLoader.cs b/IRSequencer/IRSequencer/Gui/UIAssetsLoader.cs index 48ebbbc..31be9f6 100644 --- a/IRSequencer/IRSequencer/Gui/UIAssetsLoader.cs +++ b/IRSequencer/IRSequencer/Gui/UIAssetsLoader.cs @@ -8,10 +8,11 @@ namespace IRSequencer.Gui { - [KSPAddon(KSPAddon.Startup.SpaceCentre, true)] + [KSPAddon(KSPAddon.Startup.Instantly, true)] public class UIAssetsLoader : MonoBehaviour { private AssetBundle IRAssetBundle; + private object IRAssetLoader; internal static GameObject controlWindowPrefab; internal static GameObject sequencerLinePrefab; @@ -129,12 +130,114 @@ private void LoadBundleAssets() Logger.Log("Some prefabs failed to load, bundle = " + IRAssetBundle.name); } + + private IEnumerator LoadBundleAssetsAsync() + { + var prefabsRequest = IRAssetBundle.LoadAllAssetsAsync(); + + yield return prefabsRequest; + + var prefabs = prefabsRequest.allAssets; + + int prefabsLoadedCount = 0; + for (int i = 0; i < prefabs.Length; i++) + { + if (prefabs[i].name == "SequencerMainWindowPrefab") + { + controlWindowPrefab = prefabs[i] as GameObject; + prefabsLoadedCount++; + } + if (prefabs[i].name == "SequencerLinePrefab") + { + sequencerLinePrefab = prefabs[i] as GameObject; + prefabsLoadedCount++; + } + + if (prefabs[i].name == "SequencerStateLinePrefab") + { + stateLinePrefab = prefabs[i] as GameObject; + prefabsLoadedCount++; + } + + if (prefabs[i].name == "SequenceLinePrefab") + { + sequenceLinePrefab = prefabs[i] as GameObject; + prefabsLoadedCount++; + } + + if (prefabs[i].name == "UISettingsWindowPrefab") + { + uiSettingsWindowPrefab = prefabs[i] as GameObject; + prefabsLoadedCount++; + } + + if (prefabs[i].name == "SequencerEditorWindowPrefab") + { + editorWindowPrefab = prefabs[i] as GameObject; + prefabsLoadedCount++; + } + + if (prefabs[i].name == "SequenceCommandLine") + { + sequenceCommandLinePrefab = prefabs[i] as GameObject; + prefabsLoadedCount++; + } + + if (prefabs[i].name == "BasicTooltipPrefab") + { + basicTooltipPrefab = prefabs[i] as GameObject; + prefabsLoadedCount++; + } + } + + allPrefabsReady = (prefabsLoadedCount > 7); + + spriteAssets = new List(); + var spritesRequest = IRAssetBundle.LoadAllAssetsAsync(); + + yield return spritesRequest; + + var sprites = spritesRequest.allAssets.Cast().ToArray(); + + for (int i = 0; i < sprites.Length; i++) + { + if (sprites[i] != null) + { + spriteAssets.Add(sprites[i]); + } + } + + iconAssets = new List(); + + var iconsRequest = IRAssetBundle.LoadAllAssetsAsync(); + + yield return iconsRequest; + var icons = iconsRequest.allAssets.Cast().ToArray(); + + for (int i = 0; i < icons.Length; i++) + { + if (icons[i] != null) + { + iconAssets.Add(icons[i]); + Logger.Log("Successfully loaded icon "+ icons[i].name); + } + } + + if(allPrefabsReady) + Logger.Log("Successfully loaded all prefabs from AssetBundle"); + else + Logger.Log("Some prefabs failed to load, bundle = " + IRAssetBundle.name); + + IRAssetBundle.Unload(false); + } + + public void LoadBundleFromDisk(string path) { IRAssetBundle = AssetBundle.CreateFromFile(path); - LoadBundleAssets(); - + //LoadBundleAssets(); + StartCoroutine(LoadBundleAssetsAsync()); //had to move bundle unloading further down in time due to unexplained and unreproducable on my PC issues for some users } @@ -157,11 +260,11 @@ public void Start() LoadBundleFromDisk(filePath + "ir_ui_objects.ksp"); } - + public void OnDestroy() { - Logger.Log("Unloading bundle", Logger.Level.Debug); - IRAssetBundle.Unload(false); + //Logger.Log("Unloading bundle", Logger.Level.Debug); + //IRAssetBundle.Unload(false); } } } From 65f3b5e83fbb06c9340b8f5b478ad915ff48f27c Mon Sep 17 00:00:00 2001 From: ZiwKerman Date: Fri, 22 Apr 2016 15:06:48 +0100 Subject: [PATCH 3/7] Fixing windows not remembering their position. Also added option to start Control Window in Edit Mode --- IRSequencer/IRSequencer/Gui/SequencerGUI.cs | 34 ++++++++++++++++----- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/IRSequencer/IRSequencer/Gui/SequencerGUI.cs b/IRSequencer/IRSequencer/Gui/SequencerGUI.cs index 425c2aa..bf78de8 100644 --- a/IRSequencer/IRSequencer/Gui/SequencerGUI.cs +++ b/IRSequencer/IRSequencer/Gui/SequencerGUI.cs @@ -58,7 +58,9 @@ public class SequencerGUI : MonoBehaviour public bool GUIEnabled = false; public bool guiControlWindowEditMode = false; - + + public bool alwaysStartInEditMode = false; + private bool isReady = false; private bool firstUpdate = true; @@ -537,6 +539,8 @@ private void Awake() { LoadConfigXml(); + guiControlWindowEditMode = alwaysStartInEditMode; + GameEvents.onShowUI.Add(OnShowUI); GameEvents.onHideUI.Add(OnHideUI); @@ -665,6 +669,16 @@ private void InitSettingsWindow() _settingsWindow.GetComponent().alpha = 0f; + if (SequencerSettingsWindowPosition == Vector3.zero) + { + //get the default position from the prefab + SequencerSettingsWindowPosition = _settingsWindow.transform.position; + } + else + { + _settingsWindow.transform.position = SequencerSettingsWindowPosition; + } + var closeButton = _settingsWindow.GetChild("WindowTitle").GetChild("RightWindowButton"); if (closeButton != null) { @@ -704,7 +718,12 @@ private void InitSettingsWindow() scaleText.text = string.Format("{0:#0.00}", v); }); } - + + var startEditModeToggle = _settingsWindow.GetChild ("WindowContent").GetChild ("StartEditModeHLG").GetChild ("StartEditModeToggle").GetComponent (); + startEditModeToggle.isOn = alwaysStartInEditMode; + startEditModeToggle.onValueChanged.AddListener (v => alwaysStartInEditMode = v); + + var footerButtons = _settingsWindow.GetChild("WindowFooter").GetChild("WindowFooterButtonsHLG"); var cancelButton = footerButtons.GetChild("CancelButton").GetComponent