找回密码
 立即注册
查看: 312|回复: 0

Unity android项目 AssetBundle 过多 导致首次加载太慢

[复制链接]
发表于 2022-7-5 12:14 | 显示全部楼层 |阅读模式
可以使用合包的方式,将散的ab包合并到一个大的ab中
var destFileAB = Path.Combine(Setting.EditorStreamingBundlePath, "BigAssetBundle.ab");var fileAB = new FileStream(destFileAB, FileMode.Create);var head = new byte[] {0xAA, 0xBB, 0x10, 0x12};fileAB.Write(head, 0, head.Length);// 把需要打包进ab以及ab的依赖资源全部分进ab包内for (var i = 0; i < bundleNames.Length; ++i){    var hash = bundleNames.Substring(0, bundleNames.Length - 3 /*.ab*/);    var finalName = hash + ".ab";    if (abNames.Contains(finalName)){            var nameDependencies = manifest.GetAllDependencies(bundleNames);            for (int j = 0; j < nameDependencies.Length; ++j){                    if (!abNames.Contains(nameDependencies[j])){                            abNames.Add(nameDependencies[j]);                    }                        }    }}for (var i = 0; i < bundleNames.Length; ++i){    var hash = bundleNames.Substring(0, bundleNames.Length - 3 /*.ab*/);    var finalName = hash + ".ab";    var sourceBytes = File.ReadAllBytes(Path.Combine(Setting.EditorBundleBuildCachePath, bundleNames));    if (abNames.Contains(finalName)){            fileAB.Write(sourceBytes, 0, sourceBytes.Length);    }}如何分辨是合包AB还是散包AB


再构建散包的时候,offset为0。构建合包资源的时候每个资源都记录有一个offset(资源大小字节偏移)
在加载的时候,如果offset=0的就是散包资源,否则是合包资源
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-5-30 11:35 , Processed in 0.066908 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表