Build Asset包已经过时 - 创建Asset bundle时出错

时间:2016-11-05 12:07:02

标签: c# unity3d

This is the problem

C#示例 在项目视图中从选定对象构建资产包。 编译完成后,转到“菜单” - > “资产”并选择其中一个选项 构建资产包

using UnityEngine;
using UnityEditor;
public class ExportAssetBundles {
    [MenuItem("Assets/Build AssetBundle From Selection - Track dependencies")]
    static void ExportResource () {
        // Bring up save panel
        string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
        if (path.Length != 0) {
            // Build the resource file from the active selection.
            Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
            BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, 
                                           BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets, BuildTarget.Android);
            Selection.objects = selection;
        }
    }
    [MenuItem("Assets/Build AssetBundle From Selection - No dependency tracking")]
    static void ExportResourceNoTrack () {
        // Bring up save panel
        string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
        if (path.Length != 0) {
            // Build the resource file from the active selection.
            BuildPipeline.BuildAssetBundle(Selection.activeObject, Selection.objects, path);
        }
    }
}

1 个答案:

答案 0 :(得分:3)

如果您阅读错误消息,则表示UnityEditor.BuildPipeline.BuildAssetBundle(Object, Object[], string, BuildAssesBundleOptions)已过时,并建议您应使用新的AssetBundle系统。

在Unity 5.4b中,有两个BuildAssetBundles重载并未过时。

BuildPipeline.BuildAssetBundles(string outputPath, BuildAssetBundleOptions assetBundleOptions, BuildTarget targetPlatform)

BuildPipeline.BuildAssetBundles(string outputPath, AssetBundleBuild[] builds, BuildAssetBundleOptions assetBundleOptions, BuildTarget targetPlatform)

在这里使用其中一个,它应该可以解决您的问题。

当天的课程:阅读错误消息。他们可以帮到你很多。