Skip to content

Commit

Permalink
Merge pull request #57 from ZiwKerman/V1.0-overhaul
Browse files Browse the repository at this point in the history
Minor bugfixes and Bundle handling change.
  • Loading branch information
ZiwKerman authored Oct 30, 2016
2 parents d0547aa + 092ccd3 commit 2dbd00e
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 35 deletions.
19 changes: 14 additions & 5 deletions IRSequencer/IRSequencer/Gui/SequencerGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
78 changes: 48 additions & 30 deletions IRSequencer/IRSequencer/Gui/UIAssetsLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace IRSequencer.Gui
{
[KSPAddon(KSPAddon.Startup.SpaceCentre, true)]
[KSPAddon(KSPAddon.Startup.MainMenu, false)]
public class UIAssetsLoader : MonoBehaviour
{
private AssetBundle IRAssetBundle;
Expand All @@ -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<GameObject>();
Expand Down Expand Up @@ -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 => {
Expand All @@ -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<Texture2D>)fieldInfo.GetValue(null);

fieldInfo = IRAssetsLoaderType.GetField("spriteAssets", BindingFlags.NonPublic | BindingFlags.Static);

spriteAssets = (List<Sprite>)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<Texture2D>)fieldInfo.GetValue(null);

fieldInfo = IRAssetsLoaderType.GetField("spriteAssets", BindingFlags.NonPublic | BindingFlags.Static);
spriteAssets = (List<Sprite>)fieldInfo.GetValue(null);
}
}

public void OnDestroy()
{
if(IRAssetBundle)
/*if(IRAssetBundle)
{
Logger.Log("Unloading bundle", Logger.Level.Debug);
IRAssetBundle.Unload(false);
}
}*/
}
}
}
Expand Down

0 comments on commit 2dbd00e

Please sign in to comment.