using System.Collections; using System.Collections.Generic; using UnityEditor; using UnityEngine; public class BunldesCreator : MonoBehaviour { [MenuItem("Custom Editor/Create AssetBunldes")] static void CreateAssetBunldes() { for (int i = 0; i < Selection.gameObjects.Length; i++) { // 创建 AssetBundleBuild 结构体 AssetBundleBuild bundleInfo = new AssetBundleBuild(); bundleInfo.assetBundleName = Selection.gameObjects[i].name + ".unity3d"; bundleInfo.assetNames = new string[] { Selection.gameObjects[i].name }; // string.Format("Assets/Scene0605/Scenes/Prefabs/0{0}.prefab", i) }; // 打包 AssetBundle 成文件 BuildPipeline.BuildAssetBundles("Assets/AssetBundles/", new AssetBundleBuild[] { bundleInfo }, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows); } } [MenuItem("Custom Editor/Create AssetBunldes Windows")] static void CreateAssetBunldesMain() { //获取在Project视图中选择的所有游戏对象 Object[] SelectedAsset = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets); //遍历所有的游戏对象 foreach (Object obj in SelectedAsset) { string sourcePath = AssetDatabase.GetAssetPath(obj); string targetPath = "Assets/StreamingAssets/Bundles/" + obj.name + "_win.assetbundle"; if (BuildPipeline.BuildAssetBundle(obj, null, targetPath, BuildAssetBundleOptions.CollectDependencies, BuildTarget.StandaloneWindows)) { Debug.Log(obj.name + "资源打包成功"); } else { Debug.Log(obj.name + "资源打包失败"); } } //刷新编辑器 AssetDatabase.Refresh(); } [MenuItem("Custom Editor/Create AssetBunldes Web")] static void CreateAssetBunldesWeb() { //获取在Project视图中选择的所有游戏对象 Object[] SelectedAsset = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets); //遍历所有的游戏对象 foreach (Object obj in SelectedAsset) { string sourcePath = AssetDatabase.GetAssetPath(obj); string targetPath = "Assets/StreamingAssets/Bundles/" + obj.name + ".assetbundle"; if (BuildPipeline.BuildAssetBundle(obj, null, targetPath, BuildAssetBundleOptions.CollectDependencies, BuildTarget.WebGL)) { Debug.Log(obj.name + "资源打包成功"); } else { Debug.Log(obj.name + "资源打包失败"); } } //刷新编辑器 AssetDatabase.Refresh(); } }