Version: 5.6
Method group is Obsolete

BuildPipeline.BuildAssetBundle

切换到手册
Obsolete public static bool BuildAssetBundle (Object mainAsset, Object[] assets, string pathName);
Obsolete public static bool BuildAssetBundle (Object mainAsset, Object[] assets, string pathName, out uint crc, BuildAssetBundleOptions assetBundleOptions);
Obsolete public static bool BuildAssetBundle (Object mainAsset, Object[] assets, string pathName, BuildAssetBundleOptions assetBundleOptions);
Obsolete public static bool BuildAssetBundle (Object mainAsset, Object[] assets, string pathName, out uint crc);
Obsolete public static bool BuildAssetBundle (Object mainAsset, Object[] assets, string pathName, BuildAssetBundleOptions assetBundleOptions, BuildTarget targetPlatform);
Obsolete public static bool BuildAssetBundle (Object mainAsset, Object[] assets, string pathName, out uint crc, BuildAssetBundleOptions assetBundleOptions, BuildTarget targetPlatform);

参数

mainAsset 允许您指定一个可方便地使用 AssetBundle.mainAsset 进行检索的特定对象。
assets 要写入捆绑包的一组资源。
pathName 压缩资源包的目标写入位置的文件名。
assetBundleOptions 自动包括依赖项或始终包括完整的资源,而不仅仅是确切的引用对象。
targetPlatform 要构建捆绑包的平台。
crc The optional crc output parameter can be used to get a CRC checksum for the generated AssetBundle, which can be used to verify content when downloading AssetBundles using WWW.LoadFromCacheOrDownload.

描述

构建一个资源包。

Creates a compressed unity3d file that contains a collection of assets. AssetBundles can contain any asset found in the project folder. This lets you stream resource data of any type, fully setup prefabs, textures, meshes, animations, any type of asset shown in the project window.
All paths are relative to the project folder. Like: "Assets / MyTextures / hello.png".


请注意,针对独立平台目标构建的资源包不能由 针对移动平台构建的应用程序加载,反之亦然。此外,捆绑包 在 iOS 和 Android 平台之间不兼容。

如果构建成功,该函数将返回布尔值 true,否则返回 false。

// C# Example
// Builds an asset bundle from the selected objects in the project view.
// Once compiled go to "Menu" -> "Assets" and select one of the choices
// to build the Asset Bundle

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, 0); 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); } } }

See Also: AssetBundle class, WWW.assetBundle.

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961