Skip to content

Instantly share code, notes, and snippets.

@fum1h1ro
Created February 18, 2014 10:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fum1h1ro/9068721 to your computer and use it in GitHub Desktop.
Save fum1h1ro/9068721 to your computer and use it in GitHub Desktop.
指定フォルダ以下にあるフォルダそれぞれをアセットバンドルにビルドする
import UnityEngine
import UnityEditor
import System
import System.IO
// C# の例
// プロジェクト ウィンドウの選択されたオブジェクトからアセットバンドルを作成
// コンパイルした後は "Menu" -> "Assets" へ移動して選択肢から一つを選択して
// アセットバンドルをビルド
class BuildAssetBundle:
[MenuItem("Build/Build AssetBundle From Selection - Track dependencies")]
static def ExportResource():
// 保存ウィンドウのパネルを表示
path = EditorUtility.SaveFilePanel("Save Resource", "", "New Resource", "unity3d")
if path.Length != 0:
// アクティブなセレクションに対してリソースファイルをビルド
selection = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets)
BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path,
BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets)
Selection.objects = selection
[MenuItem("Build/Build AssetBundle From Selection - No dependency tracking")]
static def ExportResourceNoTrack():
// 保存ウィンドウのパネルを表示
path = EditorUtility.SaveFilePanel("Save Resource", "", "New Resource", "unity3d")
if path.Length != 0:
// アクティブなセレクションに対してリソースファイルをビルド
BuildPipeline.BuildAssetBundle(
Selection.activeObject,
Selection.objects, path)
[MenuItem("Build/Build All Bundles")]
static def BuildAllBundles():
path = EditorUtility.SaveFolderPanel("Save Asset Bundle", "", "")
if path.Length != 0:
build_all_bundles("Assets/_SupportAssets", path) // ここのフォルダ名を変更する
// 指定フォルダ以下にあるフォルダを全てアセットバンドルにビルドする
public static def build_all_bundles(root as string, outpath as string):
dirs = get_dirs(root)
for d in dirs:
build_bundle(root + "/" + d, outpath)
// 指定フォルダをアセットバンドルにビルドする
public static def build_bundle(srcpath as string, dstpath as string):
objs = get_objs(srcpath)
if objs.Length > 0:
bundlename = Path.GetFileName(srcpath)
bundlepath = dstpath + "/" + bundlename + ".unity3d"
BuildPipeline.BuildAssetBundle(objs[0], objs, bundlepath)
private static def get_objs(path as string):
result = List[of UnityEngine.Object]()
files = get_files(path)
for f in files:
objs = AssetDatabase.LoadAllAssetsAtPath(path + "/" + f)
for o in objs:
result.Add(o)
return result.ToArray()
private static def get_dirs(path as string):
rawdirs = Directory.GetDirectories(path)
dirs = array(typeof(string), rawdirs.Length)
idx = 0
for s in rawdirs:
dirs[idx++] = Path.GetFileName(s)
return filter_ignore_entries(dirs)
private static def get_files(path as string):
rawfiles = Directory.GetFiles(path)
files = array(typeof(string), rawfiles.Length)
idx = 0
for s in rawfiles:
files[idx++] = Path.GetFileName(s)
return filter_ignore_entries(files)
private static def get_files(path as string, ext as string):
files = get_files(path)
ext = ext.ToLower()
exts = @/|/.Split(ext)
filtered = Array.FindAll(files,
{ name |
return
Array.IndexOf(exts, Path.GetExtension(name).ToLower()) >= 0
})
return filtered
private static def filter_ignore_entries(files as (string)):
return Array.FindAll(files,
{ name |
return
Path.GetFileName(name).IndexOf('.') != 0 and
Path.GetExtension(name).ToLower() != ".meta"
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment