In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail the sample analysis of the assetbundle format in Unity3D. Xiaobian thinks it is quite practical, so share it with you as a reference. I hope you can gain something after reading this article.
Unity3D's asset bundle format is not publicly available. But for better differential updates, we'd like to know about the packaging format. This allows you to create a special difference comparison merge tool, which is much better than directly doing binary difference comparison. Because you can split the data in the asset bundle into independent units, you can only compare the differences between the changed units.
The information available online isn't official; the most popular is an open source tool called disunity. It's written in java, only source code, and no formatting (which is much more important than code). By reading the code for disunity, I compiled the following notes:
Asset bundles are divided into compressed mode and uncompressed mode. Compression mode simply compresses the entire uncompressed package once with the open source lzma library. The compressed data has 13 bytes at the beginning, the first 5 bytes are the props that the API of lzma decompression needs to penetrate, and the next 4 bytes are the decompressed database length. Ignore the last 4 bytes.
After the compressed data is unpacked, it is no different from the uncompressed mode. The following only discusses the uncompressed format:
The file header of the assert bundle is serialized from such a data structure.
struct AssetBundleFileHead { struct LevelInfo { unsigned int PackSize; unsigned int UncompressedSize; }; string FileID; unsigned int Version; string MainVersion; string BuildVersion; size_t MinimumStreamedBytes; size_t HeaderSize; size_t NumberOfLevelsToDownloadBeforeStreaming; size_t LevelCount; LevelInfo LevelList[]; size_t CompleteFileSize; size_t FileInfoHeaderSize; bool Compressed;};
string is a string ending directly with\0, serialized sequentially;size_t is a 4-byte number with a large endian;bool is a single byte;vector is a structure arranged along the way.
The format of the assert bundle varies from version to version of Unity. Version indicates the format version of the bundle, starting with Unity 3.5 through version 4.x using Version = 3, only this version will be discussed below. HeaderSize should be exactly equal to the data length of the header above.
An assert bundle is composed of multiple asset files packaged together, and then these assets are packaged in sequence. serialize into structures like this:
struct AssetFileHeader { struct AssetFileInfo { string name; size_t offset; size_t length; }; size_t FileCount; AssetFileInfo File[];}; This allows us to break down multiple Assets packaged together (in most cases only one). offset represents the offset after removing HeaderSize. We can add the offset of that part to the HeaderSize to get the file offset of that part relative to the entire bundle.
For each asset, it has its own header. In addition to the basic header structure AssetHeader, there are three additional parts of the header. Disunity calls them TypeTree ObjectPath and AssetRef. Note: Format here varies with different versions of Unity3D, we only care about the format of the current version, here Format is 9 (other versions of the format, in the size end and other issues are different).
struct AssetHeader { size_t TypeTreeSize; size_t FileSize; unsigned int Format; size_t dataOffset; size_t Unknown;
Unity does a crude serialization of Asset data. The entire serialization process is performed for each object's data structure. TypeTree is a description of the data structure itself, through which each object can be deserialized.
AssetHeader is followed by TypeTree. However, this TypeTree is optional for asset bundles, because the information about the data structure can be placed in the engine beforehand (most engines only support inherent data types). TypeTree is not packaged into an asset bundle when published to mobile devices.
Each asset object has a class id, and you can find out how to deserialize it in TypeTree. The correspondence between class id and specific type can be found in the official documentation of Unity3d. But if we want to compare differences only at the object level (rather than comparing specific attributes in objects), then we don't need to untangle the details of specific objects, and that part doesn't matter. So it doesn't expand here either (if you're interested, read the disunity code, the format isn't complicated).
TypeTreeSize in AssetHeader refers to the size of the TypeTree section. Next is the descriptive data for each AssetObject.
struct ObjectHeader { struct ObjectInfo { int pathID; int offset; int length; byte classID[8]; }; int ObjectCount; ObjectInfo Object[];};
Here, all intals are 4-byte integers encoded in the little endian (unlike the big endian used by the external file format). In Unity3D, each object has a unique string path, but the asset bundle does not directly store the string, but a hashed integer, which can also be regarded as the index number of the object. The real object is placed at the end of the header, offset.
Here offset is relative to the current asset block. If you want to get the correct position relative to the entire file, it should be HeaderSize of the file + offset of the asset + dataOffset of the asset + object offset here.
Following the ObjectHeader is the AssetRef table, which records references to Assets. Used to indicate how the inner asset of the bundle references the outer asset. AssetRefTable is structured as follows:
struct AssetTable { struct AssetRef { byte GUID[8]; int type; string filePath; string assetPath; }; int Count; byte Unknown; vector Refs; This article is shared from Weixin Official Accounts- Unity3D game development essence tutorial dry goods (u3dnotes). About "Unity3D assetbundle format sample analysis" This article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.