BuildAssetBundles.cs
1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#pragma warning disable
using UnityEngine;
using UnityEditor;
public class BuildAssetBundles {
[MenuItem ("Assets/BUILD ALL BUNDLES IN ToBuild FOLDER")]
public static void BuildBundles()
{
string path = "AssetBundles/";
string[] assetsPaths = AssetDatabase.FindAssets("", new string[1] { "Assets/ToBuild" });
Debug.Log("How many assets in Assets/ToBuild: " + assetsPaths.Length);
foreach (string assetPathID in assetsPaths)
{
string assetPath = AssetDatabase.GUIDToAssetPath(assetPathID);
Object asset = AssetDatabase.LoadAssetAtPath(
assetPath, (typeof(UnityEngine.Object))
) as Object;
if (asset != null)
{
Debug.Log("Building " + assetPath);
string[] tokens = assetPath.Split('/');
tokens = tokens[tokens.Length - 1].Split('.');
buildBundle(asset, path + "STANDALONE/" + tokens[0]);
buildBundle(asset, path + "ANDROID/" + tokens[0], BuildTarget.Android);
buildBundle(asset, path + "WEBGL/" + tokens[0], BuildTarget.WebGL);
buildBundle(asset, path + "IOS/" + tokens[0], BuildTarget.iOS);
}
else Debug.Log("Ignoring " + assetPath);
}
}
private static void buildBundle(UnityEngine.Object asset, string path, BuildTarget target)
{
BuildPipeline.BuildAssetBundle(
asset,
new UnityEngine.Object[0] {},
path,
BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets,
target
);
}
private static void buildBundle(UnityEngine.Object asset, string path)
{
BuildPipeline.BuildAssetBundle(
asset,
new UnityEngine.Object[0] {},
path,
BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets
);
}
}