Skip to content

Instantly share code, notes, and snippets.

@elmirjagudin
Created April 1, 2016 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elmirjagudin/46c5fdfdc523488d4eb51903715a9641 to your computer and use it in GitHub Desktop.
Save elmirjagudin/46c5fdfdc523488d4eb51903715a9641 to your computer and use it in GitHub Desktop.
create unity asset bundle
using UnityEditor;
using UnityEngine;
using System;
using System.IO;
class MyEditorScript
{
const string ASSET_NAME = "Assets/fbx/import.fbx";
[MenuItem("Assets/orange")]
static void PerformBuild()
{
Console.WriteLine("import asset");
AssetDatabase.ImportAsset(ASSET_NAME, ImportAssetOptions.ForceSynchronousImport);
Console.WriteLine("build teh asset bundles");
// Choose the output path according to the build target.
string outputPath = Path.Combine("AssetBundles", "Windows");
if (!Directory.Exists(outputPath))
Directory.CreateDirectory(outputPath);
AssetBundleBuild[] buildMap = new AssetBundleBuild[1];
buildMap[0].assetBundleName = "import";
string[] enemyAssets = new[] { ASSET_NAME };
buildMap[0].assetNames = enemyAssets;
var manifest = BuildPipeline.BuildAssetBundles(outputPath, buildMap);
if (manifest == null)
{
Debug.LogError("no manifest, build failed probably");
}
AssetDatabase.DeleteAsset(ASSET_NAME);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment