可以使用合包的方式,将散的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[i].Substring(0, bundleNames[i].Length - 3 /*.ab*/);
var finalName = hash + ".ab";
if (abNames.Contains(finalName)){
var nameDependencies = manifest.GetAllDependencies(bundleNames[i]);
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[i].Substring(0, bundleNames[i].Length - 3 /*.ab*/);
var finalName = hash + ".ab";
var sourceBytes = File.ReadAllBytes(Path.Combine(Setting.EditorBundleBuildCachePath, bundleNames[i]));
if (abNames.Contains(finalName)){
fileAB.Write(sourceBytes, 0, sourceBytes.Length);
}
}
head
为加密,但是也没什么大用
如何分辨是合包AB还是散包AB
再构建散包的时候, offset=0
。构建合包资源的时候每个资源都记录有一个offset(资源大小字节偏移)
在加载的时候,如果 offset==0
的就是散包资源,否则是合包资源
网友评论