|
可以使用合包的方式,将散的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的就是散包资源,否则是合包资源 |
|