Version: 5.3 (switch to 5.4b)
IdiomaEnglish
  • C#
  • JS

Idioma de script

Selecciona tu lenguaje de programación favorito. Todos los fragmentos de código serán mostrados en este lenguaje.

BuildPipeline.BuildAssetBundles

Sugiere un cambio

¡Éxito!

Gracias por ayudarnos a mejorar la calidad de la documentación de Unity. A pesar de que no podemos aceptar todas las sugerencias, leemos cada cambio propuesto por nuestros usuarios y actualizaremos los que sean aplicables.

Cerrar

No se puedo enviar

Por alguna razón su cambio sugerido no pudo ser enviado. Por favor <a>intente nuevamente</a> en unos minutos. Gracias por tomarse un tiempo para ayudarnos a mejorar la calidad de la documentación de Unity.

Cerrar

Cancelar

Cambiar al Manual
public static function BuildAssetBundles(outputPath: string, assetBundleOptions: BuildAssetBundleOptions = BuildAssetBundleOptions.None, targetPlatform: BuildTarget = BuildTarget.WebPlayer): AssetBundleManifest;
public static AssetBundleManifest BuildAssetBundles(string outputPath, BuildAssetBundleOptions assetBundleOptions = BuildAssetBundleOptions.None, BuildTarget targetPlatform = BuildTarget.WebPlayer);

Parámetros

outputPath Output path for the AssetBundles.
assetBundleOptions AssetBundle building options.
targetPlatform Target build platform.

Descripción

Build all AssetBundles specified in the editor.

Use this function to build your asset bundles, after you have marked your assets for inclusion in named AssetBundles (see the manual page about building asset bundles for further details). This function builds the bundles you have specified in the editor and will return true if the build was successful and false otherwise. Additionally, error messages are shown to explain most common build failures such as incorrect target folder paths.

The outputPath is a path to a folder somewhere within the project folder where the built bundles will be saved (eg, "Assets/MyBundleFolder"). The folder will not be created automatically and the function will simply fail if it doesn't already exist.

The optional assetBundleOptions modify the way the bundle is built while the targetPlatform selects which deployment target (standalone, mobile, etc) the bundle will be used with. Note that bundles built for standalone platforms are not compatible with those built for mobiles and so you may need to produce different versions of a given bundle. See the Asset Bundle FAQ in the manual for more information about bundle compatibility among platforms.


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

Note that BuildAssetBundles will switch the Active Build Target to the targetPlatform specified while building the Asset Bundle, and it will switch back to the original Active Build Target when finished. For large projects or for consecutive AssetBundles builds, switching between Build Targets can be slow. In case you prefer not switching back to the original Build Target you can switch to the targetPlatform before you call BuildAssetBundles. For example:

See Also: AssetBundle.


public static function BuildAssetBundles(outputPath: string, builds: AssetBundleBuild[], assetBundleOptions: BuildAssetBundleOptions = BuildAssetBundleOptions.None, targetPlatform: BuildTarget = BuildTarget.WebPlayer): AssetBundleManifest;
public static AssetBundleManifest BuildAssetBundles(string outputPath, AssetBundleBuild[] builds, BuildAssetBundleOptions assetBundleOptions = BuildAssetBundleOptions.None, BuildTarget targetPlatform = BuildTarget.WebPlayer);

Parámetros

outputPath Output path for the AssetBundles.
builds AssetBundle building map.
assetBundleOptions AssetBundle building options.
targetPlatform Target build platform.

Descripción

Build AssetBundles from a building map.

This variant of the function lets you specify the names and contents of the bundles using a "building map" rather than with the details set in the editor. The map is simply an array of AssetBundleBuild objects, each of which contains a bundle name and a list of the names of asset files to be added to the named bundle.


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

See Also: AssetBundleBuild.