热更新

思考并回答以下问题:

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
using UnityEngine;
using UnityEditor;
using System.IO;

// 自动命名+打包
public class CreateAssetBundle : Editor
{
// 自动命名
[MenuItem("AssetBundle/01.SetAssetBundleName")]
static void SetAssetBundleName()
{
Object[] objects = Selection.objects; // 鼠标选中对象,可多选

foreach (Object o in objects)
{
string assetPath = AssetDatabase.GetAssetPath(o);
// Debug.Log(assetPath); // Assets/Prefab/Cube.prefab
AssetImporter assetImporter = AssetImporter.GetAtPath(assetPath);
assetImporter.assetBundleName = o.name; // cube
assetImporter.SaveAndReimport();
}
AssetDatabase.Refresh();
}

// 打包
[MenuItem("AssetBundle/02.BuildAll")]
static void BuildAll()
{
string path = Application.dataPath + "/AssetBundles/";
// Directory类需要System.IO
if (Directory.Exists(path))
{
Directory.Delete(path, true);
}
Directory.CreateDirectory(path);
BuildPipeline.BuildAssetBundles(path, BuildAssetBundleOptions.None, BuildTarget.Android);
AssetDatabase.Refresh();
}
}
0%