unity Editor 下Assetbundle 打包
来源:互联网 发布:淘宝服务器 编辑:程序博客网 时间:2024/06/13 23:34
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.IO;
public class CreateAssetBundle : MonoBehaviour
{
[MenuItem(“Custom/Create Object to It’s Single Bundle”)]
static void ExecuteSingleObjectCreateAssetBundle()
{
//清除缓存
Caching.CleanCache();
//获取Project视图中选择的所有游戏对象
Object[] SelectedAsset = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
//生成AssetBundle保存目录
if (!Directory.Exists(Application.dataPath + “/StreamingAssets”))
{
Directory.CreateDirectory(Application.dataPath + “/StreamingAssets”);
}
//遍历所有游戏对象
foreach(Object _object in SelectedAsset)
{
string sourcePath = Application.dataPath + “/StreamingAssets/” + _object.name + “.assetbundle”;
#if UNITY_ANDROID if(BuildPipeline.BuildAssetBundle(_object, null, sourcePath, BuildAssetBundleOptions.CollectDependencies, BuildTarget.Android)) { Debug.Log(_object.name + "Android端资源打包成功。"); } else { Debug.Log(_object.name + "Android端资源打包失败。"); } #elif UNITY_IPHONE if(BuildPipeline.BuildAssetBundle(_object, null, sourcePath, BuildAssetBundleOptions.CollectDependencies, BuildTarget.iOS)) { Debug.Log(_object.name + "iPhone端资源打包成功。"); } else { Debug.Log(_object.name + "iPhone端资源打包失败。"); } #elif UNITY_STANDALONE_WIN || UNITY_EDITOR //原先存在则删除掉旧有的文件 if (File.Exists(sourcePath)) { File.Delete(sourcePath); } if (BuildPipeline.BuildAssetBundle(_object, null, sourcePath, BuildAssetBundleOptions.CollectDependencies)) { Debug.Log("<color=green>" + _object.name + "</color>" + "在PC端资源打包成功。"); //刷新Project视图 AssetDatabase.Refresh(); } else { Debug.Log(_object.name + "在PC端资源打包失败。"); }
else
endif
}}[MenuItem("Custom/Create All Objects In A Bundle")]static void CreateAllObjectsAssetBundle(){ //清除缓存 Caching.CleanCache(); //生成AssetBundle保存目录 if (!Directory.Exists(Application.dataPath + "/StreamingAssets")) { Directory.CreateDirectory(Application.dataPath + "/StreamingAssets"); } string sourcePath = Application.dataPath + "/StreamingAssets/AllObjects.assetbundle"; Object[] SelectedAsset = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets); foreach (Object _object in SelectedAsset) { Debug.Log("Create AssetBundes name:" + _object.name);
if UNITY_ANDROID
if (BuildPipeline.BuildAssetBundle(_object, null, sourcePath, BuildAssetBundleOptions.CollectDependencies, BuildTarget.Android)) { Debug.Log("Android端资源打包成功。"); } else { Debug.Log("Android端资源打包失败。"); }
elif UNITY_IPHONE
if(BuildPipeline.BuildAssetBundle(_object, null, sourcePath, BuildAssetBundleOptions.CollectDependencies, BuildTarget.iOS)) { Debug.Log("iPhone端资源打包成功。"); } else { Debug.Log("iPhone端资源打包失败。"); }
elif UNITY_STANDALONE_WIN || UNITY_EDITOR
//原先存在则删除掉旧有的文件 if(File.Exists(sourcePath)) { File.Delete(sourcePath); } if (BuildPipeline.BuildAssetBundle(null, SelectedAsset, sourcePath, BuildAssetBundleOptions.CollectDependencies)) { Debug.Log("PC端资源打包成功。"); //刷新Project视图 AssetDatabase.Refresh(); } else { Debug.Log("PC端资源打包失败。"); }
else
endif
}}[MenuItem("Custom/Create Scene AssetBundle")]static void CreateSceneAssetBundle(){ //清空缓存 Caching.CleanCache(); //生成AssetBundle保存目录 if (!Directory.Exists(Application.dataPath + "/StreamingAssets")) { Directory.CreateDirectory(Application.dataPath + "/StreamingAssets"); } string sourcePath = Application.dataPath + "/StreamingAssets/AssetBundleScene.unity3d"; if (File.Exists(sourcePath)) { File.Delete(sourcePath); } string[] levels = { "Assets/Scenes/Design.unity", "Assets/Scenes/Design_2.unity" }; //打包场景 BuildPipeline.BuildPlayer(levels, sourcePath, BuildTarget.StandaloneWindows64, BuildOptions.BuildAdditionalStreamedScenes); //刷新视图 AssetDatabase.Refresh();}
}
- unity Editor 下Assetbundle 打包
- Unity Editor下选定单个资源文件打AssetBundle
- Unity 资源打包Assetbundle
- Unity 资源打包Assetbundle
- Unity 资源打包Assetbundle
- Unity资源打包Assetbundle
- [Unity]AssetBundle打包策略
- Unity AssetBundle打包
- Unity资源打包之Assetbundle
- Unity之资源打包Assetbundle
- unity assetBundle更新 打包变化
- Unity资源打包之Assetbundle
- unity AssetBundle打包以及加载
- Unity AssetBundle 打包爬坑
- Unity手游:资源打包Assetbundle
- 关于在Unity中打包AssetBundle文件
- [Unity基础]打包与读取AssetBundle
- Unity AssetBundle资源打包,Depend依赖关系
- Maven 私有库和本地库的安装与配置
- 新人报道
- 解决启动Tomcat时闪退的问题
- Django学习(四)表单,让数据库更强大
- 并发编程之归纳编
- unity Editor 下Assetbundle 打包
- Spring(6):AOP概念解释与小示例
- 转化流--pizifusheng
- Berkeley DB之JE入门
- QoS的基本原理
- pull
- 那些年犯过的错:主线程都结束了,为何进程还在执行?
- WEB网站常见受攻击方式及解决办法
- 【Android】底部弹出框BottomSheet…BottomSheetDialog…BottomSheetDialogFragment实验