Tanoda
CreateAssetBundle.cs
Go to the documentation of this file.
1using UnityEngine;
2using UnityEditor;
3using System.Collections;
4using System;
5using System.IO;
6using System.Linq;
7using GILES;
8
10{
14 public class CreateAssetBundle : Editor
15 {
16 [MenuItem("Tools/Level Editor/Build Asset Bundles")]
17 static void BuildAssetBundle()
18 {
19 if(!Directory.Exists("Assets/AssetBundles"))
20 Directory.CreateDirectory("Assets/AssetBundles");
21
22 // Make sure all assets in level editor bundles are marked with pb_MetaData
23 foreach(string bundle_name in AssetDatabase.GetAllAssetBundleNames())
24 {
25 if(pb_Config.AssetBundle_Names.Any(x => x.IndexOf(bundle_name, StringComparison.OrdinalIgnoreCase) >= 0))
26 {
27 foreach(string asset_path in AssetDatabase.GetAssetPathsFromAssetBundle(bundle_name))
28 {
29 SetMetadata(asset_path, bundle_name);
30 }
31 }
32 }
33
34 BuildPipeline.BuildAssetBundles("Assets/AssetBundles",
35 BuildAssetBundleOptions.UncompressedAssetBundle | BuildAssetBundleOptions.ForceRebuildAssetBundle,
36 EditorUserBuildSettings.activeBuildTarget );
37 }
38
39 private static void SetMetadata(string path, string name)
40 {
41 switch( pb_FileUtility.GetPathType(path) )
42 {
43 case PathType.File:
44 {
45 UnityEngine.Object obj = AssetDatabase.LoadMainAssetAtPath(path);
46
47 GameObject go = obj as GameObject;
48
49 if(go != null && PrefabUtility.GetPrefabType(go) == PrefabType.Prefab)
50 {
51 pb_MetaDataComponent metadata = go.GetComponent<pb_MetaDataComponent>();
52
53 if(!metadata)
54 metadata = go.AddComponent<pb_MetaDataComponent>();
55
56 metadata.SetAssetBundleData(name, path);
57 }
58
59 break;
60 }
61
62 case PathType.Directory:
63 {
64 foreach(string subdir in Directory.GetDirectories(path))
65 SetMetadata(subdir, name);
66
67 foreach(string asset in Directory.GetFiles(path))
68 SetMetadata(asset, name);
69
70 break;
71 }
72
73 default:
74 break;
75 }
76 }
77
78 }
79
80}
void SetAssetBundleData(string bundleName, string assetPath)
PathType
Definition: pb_Enum.cs:76