三天前我坚持 asset bundle with unity 4.x 我到目前为止所尝试的内容如下:

Making Scene Asset bundle 使用此代码片段为我成功制作.unity3d场景资产包

public class SceneAssetBundleMaker : EditorWindow {

    bool groupEnabled;

    public static string sceneName;
    static string sceneNameWithPath;
    static string sceneNameWithPathAssetBundel;
    [MenuItem("AB Scene/BuildSceneAsset")]


    public static void ShowWindow()
    {
        EditorWindow.GetWindow(typeof(SceneAssetBundleMaker));

    }

    void OnInspectorUpdate()
    {
        Repaint();
    }

    void OnGUI()
    {
        EditorGUILayout.BeginVertical("Box");
        GUILayout.Label("Enter Scene Name");
        sceneName = EditorGUILayout.TextField(sceneName);

        if (GUILayout.Button("Make Asset Bundle"))
        {
            if (sceneName != null)
                myBuild();
            else
                Debug.LogError("sceneName must be entered");
        }
        EditorGUILayout.EndVertical();

    }
     static  void myBuild()
    {
        //        string[] levels = { "Assets/Scene/SimpleBakingPlanAndBoxes.unity" };
        //string[] levels = { "Assets/Scene/"+ sceneName+ ".unity" };
        sceneNameWithPath = "Assets/_project/_scenes/" + sceneName + ".unity";
        Debug.Log("sceneNameWithPath" + sceneNameWithPath);
        string[] levels = { sceneNameWithPath };
        Debug.Log("levels : " + levels.Length);
        Debug.Log("levels 0 : " + levels[0]);

        sceneNameWithPathAssetBundel = "Assets/AssetBundles/" +sceneName + ".unity3d";
        string v = BuildPipeline.BuildStreamedSceneAssetBundle(levels, sceneNameWithPathAssetBundel, BuildTarget.StandaloneWindows);
        Debug.Log(v);
        //"Streamed-Level1.unity3d"
        //BuildPipeline.BuildStreamedSceneAssetBundle(levels, "Streamed-Level1.unity3d", BuildTarget.StandaloneWindows64);

    }   
}

而此代码用于下载场景资产包

public IEnumerator LoadSceneBundle(string assetBundleSceneName, string orignialName) {
        url = "file://" + Application.dataPath + "/AssetBundles/" + assetBundleSceneName + ".unity3d";
        Debug.Log("scene load url : " + url);
        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("Main Asset :: " + www.assetBundle.mainAsset);
            ab.LoadAll();
            Application.LoadLevel(orignialName);
            ab.Unload(false);
        }
    }

Two scene 我通过此代码切换资产包 . 代码工作正常,但并非总是如此 . 有时它会加载场景,有时候不是在我独立构建时遇到的相同情况 .

部署之后,我创建了一个AssetsBundel文件夹,并将我的assetbudel场景文件放入其中,但一切都是徒劳的 .