Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Created December 16, 2015 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tsubaki/0d961ecfaf1c0de314cb to your computer and use it in GitHub Desktop.
Save tsubaki/0d961ecfaf1c0de314cb to your computer and use it in GitHub Desktop.
AssetBundleをダイアログを指定して出力する。依存関係は知らない
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.IO;
using System.Collections.Generic;
using System.Linq;
public class ExportAssetbundle {
[MenuItem("Assets/ExportAssetBundle")]
static void ExportTargetAssets()
{
if (Selection.objects.Length == 0)
return;
// AssetBundleを出力するパスを指定
// ここで指定した名前はAssetBundle名にもなる
var path =EditorUtility.SaveFilePanel ("save assetbbundle", "Assets", "sample", null);
if (string.IsNullOrEmpty (path))
return;
// 選択中のオブジェクトからファイルを取得
var includeAssetpath = Selection.objects
.Where (c => string.IsNullOrEmpty (AssetDatabase.GetAssetPath (c)) == false)
.Select (c => AssetDatabase.GetAssetPath (c))
.ToArray ();
// AssetBundleに含めるアセットとAssetBundle名を指定
AssetBundleBuild build = new AssetBundleBuild ();
build.assetBundleName = Path.GetFileName (path);
build.assetNames = includeAssetpath;
// AssetBundleを出力
BuildPipeline.BuildAssetBundles (
Path.GetDirectoryName (path),
new AssetBundleBuild[]{ build },
BuildAssetBundleOptions.ChunkBasedCompression);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment