热更新 发表于 2019-10-18 | 分类于 Unity 本文字数: 1.1k | 阅读时长 ≈ 1 分钟 思考并回答以下问题: 123456789101112131415161718192021222324252627282930313233343536373839using 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(); }}