Last active
October 26, 2017 07:29
-
-
Save mosluce/33144172850178bf422a4c0aea6cb756 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEditor; | |
using System.Linq; | |
using System.IO; | |
using System; | |
using UnityEngine.Rendering; | |
public class AssetBundlerBuilder : Editor | |
{ | |
[MenuItem("Assets/Asset Bundle/Build for iOS")] | |
public static void BuildAssetBundle_iOS() | |
{ | |
var path = Application.dataPath + Path.DirectorySeparatorChar + "AssetBundles" + Path.DirectorySeparatorChar + "ios"; | |
BuildAssetBundle(path, BuildTarget.iOS); | |
} | |
[MenuItem("Assets/Asset Bundle/Build for Android")] | |
public static void BuildAssetBundle_Android() | |
{ | |
var path = Application.dataPath + Path.DirectorySeparatorChar + "AssetBundles" + Path.DirectorySeparatorChar + "android"; | |
BuildAssetBundle(path, BuildTarget.Android); | |
} | |
[MenuItem("Assets/Asset Bundle/Build for OS X")] | |
public static void BuildAssetBundle_OSX() | |
{ | |
var path = Application.dataPath + Path.DirectorySeparatorChar + "AssetBundles" + Path.DirectorySeparatorChar + "osx"; | |
BuildAssetBundle(path, BuildTarget.StandaloneOSXIntel64); | |
} | |
private static void BuildAssetBundle(string path, BuildTarget buildTarget) | |
{ | |
if (Selection.activeObject == null) return; | |
if (!Directory.Exists(path)) Directory.CreateDirectory(path); | |
var assets = EditorUtility.CollectDependencies(new UnityEngine.Object[] { Selection.activeObject }) | |
.Select(x => AssetDatabase.GetAssetPath(x)) | |
.Distinct() | |
.ToArray(); | |
Debug.Log(assets.Count()); | |
var builds = new AssetBundleBuild[]{ | |
new AssetBundleBuild{ | |
assetNames = assets, | |
assetBundleName = Selection.activeObject.name | |
}}; | |
BuildPipeline.BuildAssetBundles(path, builds, BuildAssetBundleOptions.ForceRebuildAssetBundle, buildTarget); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment