outputPath | AssetBundle 的输出路径。 |
assetBundleOptions | 资源包构建选项。 |
targetPlatform | 选择的目标构建平台。 |
AssetBundleManifest 列出了此构建中包含的所有 AssetBundle 的清单。
构建编辑器中指定的所有 AssetBundle。
标记要包含在命名 AssetBundle 中的资源后,
使用此函数构建您的资源包。(请参阅手册的
building AssetBundles 页面,以了解更多详细信息)。此函数
可构建您在编辑器中指定的捆绑包,如果构建成功,则返回
包括所有已含资源的清单,否则
返回 false。此外,控制台中
会显示错误消息,用于解释最常见的构建故障,如目标文件夹路径不正确。outputPath
是项目文件夹内用于保存已构建捆绑包的
文件夹的路径(例如,"Assets/MyBundleFolder")。该文件夹不会自动创建,
如果文件夹还不存在,该函数会直接失败。
可选的 assetBundleOptions
参数用于修改捆绑包的构建方式,而 targetPlatform/
用于选择捆绑包将与哪种部署目标(Windows 独立平台、Android 或 iOS 等)
配合使用。请注意,针对独立平台构建的捆绑包与
针对移动平台构建的捆绑包不兼容,因此,您可能需要针对给定捆绑包生成不同的版本。请参阅手册中
Building AssetBundles 页面的 BuildTarget 部分,以了解有关如何为不同平台创建 AssetBundle 的更多信息。
返回值的类型为 AssetBundleManifest。它包含 AssetBundle 中包含的
所有资源的列表。如果出现任何问题,则返回 Null。
// Create an AssetBundle for Windows. using UnityEngine; using UnityEditor;
public class BuildAssetBundlesExample : MonoBehaviour { [MenuItem("Example/Build Asset Bundles")] static void BuildABs() { // Put the bundles in a folder called "ABs" within the Assets folder. BuildPipeline.BuildAssetBundles("Assets/ABs", BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows); } }
outputPath | AssetBundle 的输出路径。 |
builds | AssetBundle 构建映射。 |
assetBundleOptions | 资源包构建选项。 |
targetPlatform | 目标构建平台。 |
AssetBundleManifest 列出了此构建中包含的所有 AssetBundle 的清单。
使用构建映射构建 AssetBundle。
该函数的这个变体允许您 使用"构建映射"(而非编辑器中的详细设置)指定捆绑包的名称和内容。 该映射就是 AssetBundleBuild 对象的数组,每个对象都包含 捆绑包名称和要添加到命名捆绑包中的资源文件名称列表。
using UnityEngine; using UnityEditor;
public class BuildAssetBundlesBuildMapExample : MonoBehaviour { [MenuItem("Example/Build Asset Bundles Using BuildMap")] static void BuildMapABs() { // Create the array of bundle build details. AssetBundleBuild[] buildMap = new AssetBundleBuild[2];
buildMap[0].assetBundleName = "enemybundle";
string[] enemyAssets = new string[2]; enemyAssets[0] = "Assets/Textures/char_enemy_alienShip.jpg"; enemyAssets[1] = "Assets/Textures/char_enemy_alienShip-damaged.jpg";
buildMap[0].assetNames = enemyAssets; buildMap[1].assetBundleName = "herobundle";
string[] heroAssets = new string[1]; heroAssets[0] = "char_hero_beanMan"; buildMap[1].assetNames = heroAssets;
BuildPipeline.BuildAssetBundles("Assets/ABs", buildMap, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows); } }
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.