Description
Builds an asset bundle (Unity Pro only).
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.
mainAsset lets you specify a specific object that can be conveniently retrieved using AssetBundle.mainAsset.
The compressed asset bundle file will be saved at pathName.
options allows you to automatically include dependencies or always include complete assets instead of just the exact referenced objects.
All paths are relative to the project folder. Like: "Assets/MyTextures/hello.png"
See Also: AssetBundle class, WWW.assetBundle.
using UnityEngine;
using UnityEditor;
public class ExportAssetBundles {
[
MenuItem(
"Assets/Build AssetBundle From Selection - Track dependencies")]
static void ExportResource () {
string path =
EditorUtility.SaveFilePanel (
"Save Resource",
"",
"New Resource",
"unity3d");
if (path.Length != 0) {
Object[] selection =
Selection.GetFiltered(typeof(
Object),
SelectionMode.DeepAssets);
BuildPipeline.BuildAssetBundle(
Selection.activeObject, selection, path,
BuildAssetBundleOptions.CollectDependencies |
BuildAssetBundleOptions.CompleteAssets);
Selection.objects = selection;
}
}
[
MenuItem(
"Assets/Build AssetBundle From Selection - No dependency tracking")]
static void ExportResourceNoTrack () {
string path =
EditorUtility.SaveFilePanel (
"Save Resource",
"",
"New Resource",
"unity3d");
if (path.Length != 0) {
BuildPipeline.BuildAssetBundle(
Selection.activeObject,
Selection.objects, path);
}
}
}