Skip to content

Instantly share code, notes, and snippets.

@benloong
Last active December 29, 2015 07:58
Show Gist options
  • Save benloong/7639598 to your computer and use it in GitHub Desktop.
Save benloong/7639598 to your computer and use it in GitHub Desktop.
generate assetbundle at specific assets folder
public static ExportMenu {
[MenuItem("Export/Config")]
static public void ExportConfig()
{
string platInfo = "PC";
BuildTarget target = BuildTarget.StandaloneWindows;
#if UNITY_ANDROID
target = BuildTarget.Android;
platInfo = "Android";
#endif
#if UNITY_IPHONE
target = BuildTarget.iPhone;
platInfo = "IOS";
#endif
List<Object> assets = new List<Object>();
Object selection = Selection.activeObject;
var configfolder = AssetDatabase.LoadAssetAtPath("Assets/Resources/config", typeof(Object));
Selection.activeObject = configfolder;
foreach (Object o in Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets))
{
assets.Add(o);
}
Selection.activeObject = selection;
var directory = "../release/"+platInfo + "/config/";
if(!Directory.Exists(directory)) {
Directory.CreateDirectory(directory);
}
string basePath = directory+"maincfg.u3ys";
BuildPipeline.BuildAssetBundle(null, assets.ToArray(), basePath, BuildAssetBundleOptions.CollectDependencies|BuildAssetBundleOptions.CompleteAssets, target);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment