unity编辑器扩展--AssetBundle菜单
2017-10-31 17:54
399 查看
选中预制体,点击菜单按钮打包到固定文件夹
using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; using UnityEditor; public class CreatAssetBundles{ const string PATH = "Data/asset/"; const string fileEndName = ".aseetBundle"; [MenuItem("MyTools/打包AB/打包选中的对象")] static void CreateAssetBundlesMain() { Object[] selectedAsset = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets); if (selectedAsset.Length == 0) { Debug.LogError("未选中任何对象!"); return; } string toPath = GetAssetBundlePath(); foreach (var obj in selectedAsset) { string objName = obj.name; //Debug.Log(toPath); if (!Directory.Exists(toPath)) { Directory.CreateDirectory(toPath); } string targetPath = toPath + objName.ToLower() + fileEndName; if(BuildPipeline.BuildAssetBundle(obj,null,targetPath,BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.ChunkBasedCompression | BuildAssetBundleOptions.DeterministicAssetBundle, GetTargetPlatform())) { Debug.Log(objName + "资源打包成功"); }else { Debug.Log(objName + "资源打包失败"); } } } [MenuItem("MyTools/打包AB/按AB包名打包所以对象")] static void BuildleAllAssetBundles() { BuildPipeline.BuildAssetBundles("Assets/Data",BuildAssetBundleOptions.ChunkBasedCompression | BuildAssetBundleOptions.DeterministicAssetBundle, GetTargetPlatform()); } public static string GetAssetBundlePath() { BuildTarget target = GetTargetPlatform(); return Application.dataPath + PATH + target.ToString().ToLower() + "/"; } public static BuildTarget GetTargetPlatform() { BuildTarget target = BuildTarget.Android; #if UNITY_STANDALONE target = BuildTarget.StandaloneWindows; #elif UNITY_IPHONE target = BuildTarget.iOS; #elif UNITY_ANDROID target = BuildTarget.Android; #endif return target; } }
相关文章推荐
- Unity 5.X扩展编辑器之打包assetbundle
- Unity 5.X扩展编辑器之打包assetbundle
- Unity编辑器扩展学习笔记(一)——添加菜单选项
- Unity5.x 编辑器中 获取所有标记的 AssetBundle 文件
- 扩展Unity编辑器菜单指南
- 关于AssetBundle打包的编辑器扩展
- Unity编辑器拓展【菜单扩展】
- Unity 编辑器环境下不能正确加载Android Assetbundle 中的 Shader 解决方法
- 【unity学习笔记】在unity中扩展编辑器添加菜单
- Unity3D热更新<二> 编辑器扩展和打包AssetBundle
- Unity 编辑器环境下不能正确加载Android Assetbundle 中的 Shader 解决方法
- Unity编辑器扩展学习笔记(二)——给创建的菜单选项添加快捷键
- Unity编辑器扩展:如何把asset 格式的资源转成png
- Unity 编辑器环境下不能正确加载Android Assetbundle 中的 Shader
- Unity-AssetBundle爬坑记
- 实力封装:Unity打包AssetBundle(番外篇)
- 实力封装:Unity打包AssetBundle(四)
- unity AssetBundle的资源管理
- Unity Assetbundle shader(丢失)不正确显示的问题
- Unity AssetBundle 爬坑!!!!!!!