Skip to content

Instantly share code, notes, and snippets.

@hisasann
Created April 16, 2014 08:46
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 hisasann/10834788 to your computer and use it in GitHub Desktop.
Save hisasann/10834788 to your computer and use it in GitHub Desktop.
AssetBundle用のエディター拡張
// C# の例
// プロジェクト ウィンドウの選択されたオブジェクトからアセットバンドルを作成
// コンパイルした後は "Menu" -> "Assets" へ移動して選択肢から一つを選択して
// アセットバンドルをビルド
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);
// via https://gist.github.com/yaeda/5410868
// require iOS Pro, Android Pro Lisence
// for Android
BuildPipeline.BuildAssetBundle(Selection.activeObject,
selection, path + ".android.unity3d",
BuildAssetBundleOptions.CollectDependencies |
BuildAssetBundleOptions.CompleteAssets,
BuildTarget.Android);
// for iPhone
BuildPipeline.BuildAssetBundle(Selection.activeObject,
selection, path + ".iphone.unity3d",
BuildAssetBundleOptions.CollectDependencies |
BuildAssetBundleOptions.CompleteAssets,
BuildTarget.iPhone);
// for WebPlayer
BuildPipeline.BuildAssetBundle(Selection.activeObject,
selection, path + ".unity3d",
BuildAssetBundleOptions.CollectDependencies |
BuildAssetBundleOptions.CompleteAssets,
BuildTarget.WebPlayer);
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);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment