Unity5.x依赖打包
2016-06-03 10:14
417 查看
unity5已经封装好了接口,所以依赖打包并没有那么神秘和复杂了。
打包:
1.定义好资源的assetBundleName
2.BuildPipeline.BuildAssetBundles,指定资源目录和压缩类型
生成:
1.Assetbundle文件,加载时的首要文件,包含所有资源的依赖信息
2.每个文件对应一个.manifest,不用管他,但是可以打开查看他引用了哪些资源。
加载:
1.获取AssetBundle文件
2.LoadAsset(“AssetBundleManifest”)转换为AssetBundleManifest
3.通过manifest.GetAllDependencies(“测试文件”),获取它依赖的ab,得到的是AB数组,并下载它
4.最后下载名为(测试文件)的资源即可。
测试代码:
坑tips:
如果材质球的名称和它引用的贴图名称一样,材质球内存占有量就会像包含了贴图的内存一样。
换版本tips:
4.6项目移植到5.0.2,ab包无法加载,重新打包即可。
不改打包代码,多数文件大小增大2k
改为最新打包代码,不做依赖,多数文件大小增大2-4%左右
打包:
1.定义好资源的assetBundleName
2.BuildPipeline.BuildAssetBundles,指定资源目录和压缩类型
生成:
1.Assetbundle文件,加载时的首要文件,包含所有资源的依赖信息
2.每个文件对应一个.manifest,不用管他,但是可以打开查看他引用了哪些资源。
加载:
1.获取AssetBundle文件
2.LoadAsset(“AssetBundleManifest”)转换为AssetBundleManifest
3.通过manifest.GetAllDependencies(“测试文件”),获取它依赖的ab,得到的是AB数组,并下载它
4.最后下载名为(测试文件)的资源即可。
测试代码:
using UnityEngine; using System.Collections; public class LoadAssetbundle : MonoBehaviour { void Start() { // 1.加载Manifest文件 AssetBundle manifestBundle=AssetBundle.CreateFromFile(Application.dataPath +"/ab/Assetbundle"); if(manifestBundle != null) { AssetBundleManifest manifest = (AssetBundleManifest)manifestBundle.LoadAsset("AssetBundleManifest"); // 2.获取依赖文件列表 string[] cubedepends = manifest.GetAllDependencies("assets/res/1.prefab"); AssetBundle[] dependsAssetbundle = new AssetBundle[cubedepends.Length]; for(int index = 0; index < cubedepends.Length; index++) { // 3.加载所有的依赖资源 dependsAssetbundle[index]=AssetBundle.CreateFromFile( Application.dataPath +"/../Assetbundle/"+cubedepends[index]); } // 4.加载资源 AssetBundle cubeBundle=AssetBundle.CreateFromFile( Application.dataPath +"/ab/assets/res/1.prefab" ); GameObject cube=cubeBundle.LoadAsset("1") as GameObject; if(cube!=null) { Instantiate(cube); } } } }
坑tips:
如果材质球的名称和它引用的贴图名称一样,材质球内存占有量就会像包含了贴图的内存一样。
换版本tips:
4.6项目移植到5.0.2,ab包无法加载,重新打包即可。
不改打包代码,多数文件大小增大2k
改为最新打包代码,不做依赖,多数文件大小增大2-4%左右
相关文章推荐
- unity实现多点触控代码
- 在Unity中实现动画的正反播放代码
- Unity UGUI教程之实现滑页效果
- unity实现摄像头跟随
- Unity3D上路_01-2D太空射击游戏
- Unity3D上路_02-第一视角射击游戏
- Unity3D上路_03-塔防游戏
- Unity3D上路_04-基础资源介绍
- Unity3D上路_05-网络相关
- Unity3D-5.3.5发布VR项目到Android
- [软件资讯]Unity已支持将3D游戏导出成Flash
- ShaderLab: Pass
- Unity 武器拖尾效果
- unity常见问题之20题
- Unity3D动画存储插件
- unity 赛车相机跟随物体移动
- uLua中遇到的问题
- Unity3d 协程、调用函数、委托
- Unity3d摄像机Camera参数详解
- Unity3d多线程