首页 技术 正文
技术 2022年11月9日
0 收藏 888 点赞 4,526 浏览 1647 个字

http://blog.sina.com.cn/s/blog_89d90b7c0102w2ox.html

unity5已经封装好了接口,所以依赖打包并没有那么神秘和复杂了。

打包:

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%左右

tips:

如果做依赖,会生成很多零碎的文件,开发期不建议使用,以免增加不必要的工作量。和美术定义好资源规范才是重点。(个人意见,不喜随你便Unity学习(六)5.x依赖打包)

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,488
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,736
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,487
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,127
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,289