如何在Unity中加载资产包场景4

时间:2015-11-02 05:52:40

标签: unity3d assetbundle

我制作了像这样的场景的资产包

    [MenuItem("MFKJ/BuildSceneAsset")]
    static void myBuild() {

        string[] levels = { "Assets/Scene/Scene2.unity" };
        string v = BuildPipeline.BuildStreamedSceneAssetBundle(levels, "Assets/AssetBundles/Streamed-Level2.unity3d", BuildTarget.StandaloneWindows);
        Debug.Log(v);
        //"Streamed-Level1.unity3d"
        //BuildPipeline.BuildStreamedSceneAssetBundle(levels, "Streamed-Level1.unity3d", BuildTarget.StandaloneWindows64);

}

这在指定的文件夹中创建了一个.unity3d assetbundle文件。 现在,在运行时,我使用此代码从资产包中加载场景形成另一个场景。

public string url;
    // Use this for initialization
    void Start () {

        url = "file://" + Application.dataPath + "/AssetBundles/Streamed-Level2.unity3d";
        Debug.Log("scene load url : " + url);
        StartCoroutine(LoadSceneBundle());
    }

    // Update is called once per frame
    void Update () {

    }

    public IEnumerator LoadSceneBundle() { 
        using (WWW www = WWW.LoadFromCacheOrDownload(url,1)){
            yield return www;
            if (www.error != null) {
                throw new Exception("WWW donwload had an error : " + url + " " + www.error);
                //Debug.Log("");
            }
            AssetBundle ab = www.assetBundle;
            Debug.Log(www.assetBundle.mainAsset);

            //GameObject gm = ab.mainAsset as GameObject;
            //Debug.Log("Scene2PassValue : " + gm.name);
            //Instantiate(gm);
            //ab.LoadAll(typeof(GameObject));
            ab.LoadAll();

            ab.Unload(false);
        }
    }

但遗憾的是,这并未从资产包中加载流式场景或流式场景的任何资产。我错过了什么?

0 个答案:

没有答案
相关问题