unity assets bundle extractor 1.7 32bit怎么打开
创建AssetBundle1.创建一个空的Prefab,命名Cube,然后创建一个Cube,将其拉到刚创建好的Prefab2.新建一个脚本ExportAssetBundles.cs(代码来自官方文档),保存在Asset/Editor目录下[csharp]viewplaincopyprint?//在Unity编辑器中添加菜单[MenuItem("Assets/BuildAssetBundleFromSelection")]staticvoidExportResourceRGB2(){//打开保存面板,获得用户选择的路径stringpath=EditorUtility.SaveFilePanel("SaveResource","","NewResource","assetbundle");if(path.Length!=0){//选择的要保存的对象Object[]selection=Selection.GetFiltered(typeof(Object),SelectionMode.DeepAssets);//打包BuildPipeline.BuildAssetBundle(Selection.activeObject,selection,path,BuildAssetBundleOptions.CollectDependencies|BuildAssetBundleOptions.CompleteAssets,BuildTarget.StandaloneWindows);}}这时我们将看到Asset下面出现BuildAssetBundleFromSelection和BuildScene3.选中预设Cube,运行BuildAssetBundleFromSelectionBitAsset。这时会弹出一个保存框,将其命名为cube.unity3d(这里为了测试方便,放在c盘。实际项目中,我们是需要将他们放在web服务器,供所有客户端下载更新)4.新建一个场景scene1.unity,上面放置几个模型,然后保存5.选中该场景,在之前的ExportAssetBundles.cs脚本中添加打包场景的函数,运行Assets->BuildScene,保存为scene1.unity3d(这里为了测试方便,也放在c盘)[csharp]viewplaincopyprint?[MenuItem("Assets/SaveScene")]staticvoidExportScene(){//打开保存面板,获得用户选择的路径stringpath=EditorUtility.SaveFilePanel("SaveResource","","NewResource","unity3d");if(path.Length!=0){//选择的要保存的对象Object[]selection=Selection.GetFiltered(typeof(Object),SelectionMode.DeepAssets);string[]scenes={"Assets/scene1.unity"};//打包BuildPipeline.BuildPlayer(scenes,path,BuildTarget.StandaloneWindows,BuildOptions.BuildAdditionalStreamedScenes);}}注意事项a.AssetBundle的保存后缀名可以是assetbundle或者unity3db.BuildAssetBundle要根据不同的平台单独打包,BuildTarget参数指定平台,如果不指定,默认的webplayer加载AssetBundle我们通过一个简单的代码来演示如何加载assetbundle,包括加载普通asset和场景。[csharp]viewplaincopyprint?usingSystem;usingUnityEngine;usingSystem.Collections;publicclassLoad:MonoBehaviour{privatestringBundleURL="file:///C:/cube.assetbundle";privatestringSceneURL="file:///C:/scene1.unity3d";voidStart(){//BundleURL="file//"+Application.dataPath+"/cube.assetbundle";Debug.Log(BundleURL);StartCoroutine(DownloadAssetAndScene());}IEnumeratorDownloadAssetAndScene(){//下载assetbundle,加载Cubeusing(();我们在程序加载的时候必须保证先加载公共对象。否则,只能是在各个对象加载成功后,再通过程序手动添加进来,比较繁琐。在实际项目中,由于是团队开发,对象间的依赖关系通常会比较凌乱,最好在开发周期就定好相关的规范约束,方便管理。
评论