Skip to content

Instantly share code, notes, and snippets.

Created March 6, 2015 07:02
Show Gist options
  • Save marukun318/2c07787b99339045bb64 to your computer and use it in GitHub Desktop.
Save marukun318/2c07787b99339045bb64 to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.IO;
public class BuildScript
const string kAssetBundlesOutputPath = "AssetBundles";
// アセットバンドル化するフォルダの設置場所
private static string assetTopDir = "Assets/Data/"; // ※大文字小文字は区別される
[MenuItem( "AssetBundles/Build AssetBundles" )]
public static void BuildAssetBundles()
// Choose the output path according to the build target.
string outputPath = Path .Combine(kAssetBundlesOutputPath, "");
if (!Directory .Exists(outputPath))
BuildPipeline.BuildAssetBundles(outputPath, BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget);
private static void SetAssetName(Object obj)
var path = AssetDatabase.GetAssetPath(obj);
// AssetImporterも取得
AssetImporter importer = AssetImporter.GetAtPath(path);
if (path.IndexOf("Resources/" ) >= 0)
string abname = path.Replace(assetTopDir, "");
int idx = abname.LastIndexOf('.' );
if (idx != -1)
abname = abname.Substring(0, idx) + ".unity3d";
abname = path;
importer.assetBundleName = abname;
importer.assetBundleVariant = "";
[MenuItem( "Assets/Set Assetbundle name" )]
public static void SelectionAsset()
// Build the resource file from the active selection.
Object[] selection = Selection.GetFiltered(typeof( Object), SelectionMode .DeepAssets);
foreach (var obj in selection)
Copy link

In Unity5, you put in the Editor folder, same the filename and iassetbundle name attached at once to the selected asset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment