Hey Guys!,
I’ve been trying to load an asset bundle from an editor script but I’m just unable to do it :/…
you might think “Why would you do that?” well… the answer is simple.
I have a Library of asset bundles and have a program to place the assets easily so what I just need is to load lets say the asset X which resides in the address http://myserver.com/myasset.unity3dbundle
and load in the Editor, so I can calculate a light map of the generated scene…
Here is what I have written:
`
using UnityEngine;
using UnityEditor;
using System.Collections;
public class DecryptAssetBundle : EditorWindow {
private string assetURL = "";
private static WWW request;
[MenuItem("Bundles/Decrypt Asset Bundle")]
static void Init () {
DecryptAssetBundle window = EditorWindow.GetWindow(typeof(DecryptAssetBundle)) as DecryptAssetBundle;
window.position = new Rect(Screen.width/2,Screen.height/2, 400,150);
}
void OnGUI()
{
assetURL = EditorGUILayout.TextField("Asset bundle URL: ", assetURL);
GUILayout.BeginHorizontal();
if(GUILayout.Button("Clear"))
{
assetURL = "";
}
if(GUILayout.Button("Decrypt"))
{
MonoBehaviour m = new MonoBehaviour(); //Shouldnt do this but is the only way to make StartCoproutine work
m.StartCoroutine(LoadAsset(assetURL));//doesnt work!!!!
}
GUILayout.EndHorizontal();
}
private IEnumerator LoadAsset(string s)
{
Debug.Log("Loading " + s + " ...");
request = new WWW(s);
yield return request;
if(request.error != null)
Debug.LogError(request.error);
GameObject g = (GameObject) request.assetBundle.mainAsset as GameObject;
Instantiate(g);
}
}
`
Any help would be greatly appreciated
Thanks!