Loading GameObjects from assetbundles is easy since there is documentation available. But how do I load a scene?
...
using(www = WWW.LoadFromCacheOrDownload(moduleAddress, 1)) {
yield return www;
if (string.IsNullOrEmpty(www.error)) {
AssetBundle assetBundle = www.assetBundle;
if (assetBundle != null) {
string[] scenePath = assetBundle.GetAllScenePaths();
Debug.Log("scenepath: " + scenePath[0]);
Application.LoadLevel(scenePath[0]);
}
else Debug.Log("assetBundle is null");
assetBundle.Unload(false);
www.Dispose();
}
else Debug.Log(www.error);
}
This line fails with: IndexOutOfRangeException: Array index is out of range:
Debug.Log("scenepath: " + scenePath[0]);
Do I have to do something else first or is there something wrong with my asset bundle?
I build the asset bundle just like I did it with gameObjects: Select the Scene in the Project view, assigned it to an asset bundle at the bottom of the inspector and then run the Editor script:
[MenuItem("Assets/Build AssetBundles - Editor")]
static void BuildAssetBundles_Editor ()
{
BuildPipeline.BuildAssetBundles ( "AssetBundles/Editor",
BuildAssetBundleOptions.None,
BuildTarget.StandaloneWindows);
}
I just can’t find a decent example on the internet and the documentation does not explain it either. So I’m asking here.