using UnityEngine; using System.Collections; using UnityEditor; using System; using System.Collections.Generic; using System.IO; public class AutoCreateAssetBundle : MonoBehaviour { static ArrayList arr = new ArrayList(); static Hashtable arrObj = new Hashtable(); static UnityEngine.Object [] selection; static uint INCLUDE_COUNT = 2; static int success_cnt; [MenuItem("Assets/Build [ Auto Create ]")] static void ExportResourceNoTrack () { string saveDir = EditorUtility.OpenFolderPanel("Select Save Path", "", ""); // Debug.Log("saveDir: " + saveDir); if( saveDir.Length != 0 ){ string path = AssetDatabase.GetAssetPath(Selection.activeObject); path = path.Substring(0, path.LastIndexOf('/')); if (path.Length != 0) { UnityEngine.Object [] objs = Selection.objects; foreach(UnityEngine.Object obj in objs){ Debug.Log("\t\t\t\t\t\t\t\t\t" + obj.name); arr.Add(obj.name); arrObj.Add(obj.name, obj); } foreach(string n in arr){ int cnt = 0; selection = new UnityEngine.Object[1]; UnityEngine.Object t = AssetDatabase.LoadMainAssetAtPath(path); t.name = n; selection[0] = arrObj[n] as UnityEngine.Object; Debug.Log( " -> " + selection[0] + " / " + arrObj.Contains(n) + " / " + arrObj.Count + " / " + n + " / " + t + " / " + t.name + " / " + path + " / " + selection + " / " + selection.Length ); string bundlePath = saveDir + "/" + n + ".bfbundle"; BuildAssetBundleOptions options = BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets; // BuildAssetBundleOptions.DisableWriteTypeTree | BuildAssetBundleOptions.DeterministicAssetBundle; if( BuildPipeline.BuildAssetBundle(t, selection, bundlePath, options, BuildTarget.iPhone) ) { Debug.Log("Success. (" + success_cnt + ") " + bundlePath); success_cnt++; }else { Debug.LogWarning("Failed"); } cnt++; } Debug.LogWarning("[ All Completed ] " + " bundle : " + success_cnt); for( int k = 0; k < selection.Length; ++k){ selection[k] = null; Selection.objects[k] = null; } arr.Clear(); arrObj.Clear(); success_cnt = 0; } } } }