Skip to content

Instantly share code, notes, and snippets.

@marukun318
Created March 6, 2015 07:02
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save marukun318/2c07787b99339045bb64 to your computer and use it in GitHub Desktop.
Save marukun318/2c07787b99339045bb64 to your computer and use it in GitHub Desktop.
Unity5で選択したファイルにアセットバンドルの名前を自動で付ける
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))
Directory.CreateDirectory(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)
return;
string abname = path.Replace(assetTopDir, "");
int idx = abname.LastIndexOf('.' );
if (idx != -1)
{
abname = abname.Substring(0, idx) + ".unity3d";
}
else
{
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)
{
SetAssetName(obj);
}
}
}
@marukun318
Copy link
Author

Unity5で、Editorフォルダの中に入れると、選択したアセットに一括でそのファイル名と同じアセットバンドル名が付くようになります。
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