我正在试验 Unity3d AssetBundles。我正在尝试使用其对象加载场景。我有这个简单的代码来创建我的资产包:
[MenuItem ("Build/BuildAssetBundle")]
static void myBuild(){
string[] levels = {"Assets/main.unity"};
BuildPipeline.BuildStreamedSceneAssetBundle(levels,"Streamed-Level1.unity3d",BuildTarget.Android);
}
我使用上面的代码从一个场景中构建资产包,该场景在中心有一个相机和一个立方体。
我有这个代码来加载它:
using UnityEngine;
using System.Collections;
public class loader : MonoBehaviour {
public GUIText debugger;
private string url = "http://www.myurl.com/Streamed-Level1.unity3d";
// Use this for initialization
IEnumerator Start () {
Debug.Log("starting");
WWW www = WWW.LoadFromCacheOrDownload(url,1);
if(www.error != null)
{
Debug.LogError(www.error);
}
yield return www;
Debug.Log("after yield");
AssetBundle bundle = www.assetBundle;
bundle.LoadAll();
Debug.Log("loaded all");
Application.LoadLevel("main");
}
// Update is called once per frame
void Update () {
}
}
问题似乎是当它到达 loadAll 时它停止了。
如果有人可以帮助我,我将不胜感激。
非常感谢