|
1 | 1 | # UnityDataTools |
2 | 2 |
|
3 | | -The UnityDataTool is a set of command line tools showcasing what can be done with the |
4 | | -UnityFileSystemApi native dynamic library. The main purpose of these tools is to analyze the |
5 | | -content of Unity data files. You can directly jump |
6 | | -[here](https://github.com/Unity-Technologies/UnityDataTools/blob/main/UnityDataTool/README.md) |
7 | | -if your goal is to understand how to use the UnityDataTool command-line tool. |
| 3 | +The UnityDataTool is a command line tool and showcase of the UnityFileSystemApi native dynamic library. |
| 4 | +The main purpose is for analysis of the content of Unity data files, for example AssetBundles and |
| 5 | +Player content. |
8 | 6 |
|
9 | | -The UnityFileSystemApi library is distributed in the Tools folder of the Unity editor (starting in |
10 | | -version 2022.1.0a14). For simplicity, it is also included in this repository. The library is somewhat |
11 | | -backward compatible, which means that it can read data files generated by any previous version of |
12 | | -Unity. Ideally, you should copy UnityFileSystemApi (.dll/.dylib) from Unity Editor install path |
13 | | -`Data/Tools/` subfolder to `UnityDataTool/UnityFileSystem/` of an Engine version that produced |
14 | | -serialized data you want to analyze. |
15 | | - |
16 | | -## What is the purpose of the UnityFileSystemApi native library? |
17 | | - |
18 | | -The purpose of the UnityFileSystemApi is to expose the functionalities of the WebExtract and |
19 | | -binary2text tools, but in a more flexible way. To fully understand what it means, let's first |
20 | | -discuss how Unity generates the data files in a build. The data referenced by the scenes in a build |
21 | | -is called the Player Data and is contained in SerializedFiles. A SerializedFile is the file format |
22 | | -used by Unity to store its data. In builds, they contain the serialized assets in the target's |
23 | | -platform-specific format. |
24 | | - |
25 | | -When using AssetBundles or Addressables, things are slightly different. Firstly, note that |
26 | | -Addressables are AssetBundles on disk so we will only use the term AssetBundle in the remaining of |
27 | | -this document. AssetBundles are archive files (similar to zip files) that can be mounted at |
28 | | -runtime. They contain SerializedFiles, but contrary to those of the Player Data, they include what |
29 | | -is called a TypeTree<sup>[1](#footnote1)</sup>. |
30 | | - |
31 | | -> Note: it is possible to generate TypeTrees for the Player data starting in Unity 2021.2. |
32 | | -> To do so, the *ForceAlwaysWriteTypeTrees* Diagnostic Switch must be enabled in the Editor |
33 | | -> Preferences (Diagnostic/Editor section). |
34 | | -
|
35 | | -The TypeTree is a data structure exposing how objects have been serialized, i.e. the name, type and |
36 | | -size of their properties. It is used by Unity when loading an AssetBundle that was built by a |
37 | | -previous Unity version (so you don't necessarily have to update all AssetBundles after upgrading a |
38 | | -project to a newer version of Unity). |
39 | | - |
40 | | -The content of a SerializedFile including a TypeTree can be converted to a human-readable format |
41 | | -using the binary2text tool that can be found in the Tools folder of Unity. In the case of |
42 | | -AssetBundles, the SerializedFiles must first be extracted using the WebExtract tool that is also in |
43 | | -the Tools folder. For the Player Data, there is no TypeTree because it is included in a build and |
44 | | -therefore not sensitive to Unity version upgrades. Skipping TypeTrees yields reduced file size and |
45 | | -improved loading times. |
46 | | - |
47 | | -The text file generated by binary2text can be very useful to |
48 | | -diagnose issues with a build, but they are usually very large and difficult to navigate. Because of |
49 | | -this, a tool called the [AssetBundle Analyzer](https://github.com/faelenor/asset-bundle-analyzer) |
50 | | -was created to make it easier to extract useful information from these files in the form of a |
51 | | -SQLite database. The AssetBundle Analyzer has been quite successful but it has several issues. It |
52 | | -is extremely slow as it runs WebExtract and binary2text on all the AssetBundles of a project and |
53 | | -has to parse very large text files. It can also easily fail because the syntax used by binary2text |
54 | | -is not standard and can even be impossible to parse in some occasions. |
| 7 | +The [command line tool](./UnityDataTool/README.md) runs directly on Unity data files, without requiring the Editor to be running. It covers functionality of the Unity tools WebExtract and binary2text, with better performance. And it adds a lot of additional functionality, for example the ability to create a SQLite database for detailed analysis of build content. It is designed to scale for large build outputs and has been used to fine-tune big Unity-based games. |
55 | 8 |
|
56 | | -The UnityFileSystemApi library has been created to expose WebExtract and binary2text |
57 | | -functionalities. This enables the creation of tools that can read Unity data files with TypeTrees. |
58 | | -With it, it becomes very easy to create a binary2text-like tool that can output the data in any |
59 | | -format or a new faster and simpler AssetBundle Analyzer. |
| 9 | +The command line tool uses the UnityFileSystemApi library to access the content of Unity Archives and Serialized files, which are Unity's primary binary formats. This repository also serves as a reference for how this library could be used as part of incorporating functionality into your own tools. |
60 | 10 |
|
61 | 11 | ## Repository content |
62 | 12 |
|
63 | 13 | The repository contains the following items: |
64 | | -* UnityFileSystem: source code of a .NET class library exposing the functionalities or the |
65 | | - UnityFileSystemApi native library. |
66 | | -* UnityFileSystem.Tests: test suite for the UnityFileSystem library. |
67 | | -* UnityFileSystemTestData: the Unity project used to generate the test data. |
68 | | -* TestCommon: a helper library used by the test projects. |
69 | | -* [UnityDataTool](UnityDataTool/README.md): a command-line tool providing several features that can |
70 | | - be used to analyze the content of Unity data files. |
| 14 | +* [UnityDataTool](UnityDataTool/README.md): a command-line tool providing access to the Analyzer, TextDumper and other class libraries. |
71 | 15 | * [Analyzer](Analyzer/README.md): a class library that can be used to extract key information |
72 | | - from Unity data files and output it into a SQLite database (similar to the |
73 | | - [AssetBundle Analyzer](https://github.com/faelenor/asset-bundle-analyzer)). |
| 16 | + from Unity data files and output it into a SQLite database. |
74 | 17 | * [TextDumper](TextDumper/README.md): a class library that can be used to dump SerializedFiles into |
75 | 18 | a human-readable format (similar to binary2text). |
76 | 19 | * [ReferenceFinder](ReferenceFinder/README.md): a class library that can be used to find |
77 | 20 | reference chains from objects to other objects using a database created by the Analyzer |
| 21 | +* UnityFileSystem: source code and binaries of a .NET class library exposing the functionalities or the |
| 22 | + UnityFileSystemApi native library. |
| 23 | +* UnityFileSystem.Tests: test suite for the UnityFileSystem library. |
| 24 | +* UnityFileSystemTestData: the Unity project used to generate the test data. |
| 25 | +* TestCommon: a helper library used by the test projects. |
| 26 | + |
| 27 | +## Getting the UnityFileSystemApi library |
| 28 | + |
| 29 | +The UnityFileSystemApi library is distributed in the Tools folder of the Unity editor (starting in |
| 30 | +version 2022.1.0a14). For convenience this repository includes a copy of the Unity 2022 Windows, Mac and Linux builds of the |
| 31 | +library, in the `UnityFileSystem/` directory. The library is somewhat backward compatible, |
| 32 | +which means that it can read data files generated by any previous version of |
| 33 | +Unity. Ideally, you should copy UnityFileSystemApi (.dll/.dylib) from Unity Editor install path |
| 34 | +`Data/Tools/` subfolder to `UnityDataTool/UnityFileSystem/` of an Engine version that produced |
| 35 | +serialized data you want to analyze. |
78 | 36 |
|
79 | 37 | ## How to build |
80 | 38 |
|
| 39 | +Currently, we do not host builds of UnityDataTools, you will need to clone or download this repo and build it yourself. |
| 40 | + |
81 | 41 | 1) The projects in this solution require the [.NET 9.0 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/9.0). |
82 | | -2) Copy `UnityFileSystemApi` library from UnityEditor installation |
83 | | -`{UnityEditor}/Data/Tools/` to `UnityDataTool/UnityFileSystem/` before building. |
| 42 | +2) Copy `UnityFileSystemApi` library from your Unity Editor installation, in |
| 43 | +`{UnityEditor}/Data/Tools/` to `UnityDataTool/UnityFileSystem/`. This step is typically optional, because a previously built version of the library is included in the repo that can read the output from most Unity Versions. |
84 | 44 | 3) Build using `dotnet build -c Release` |
85 | 45 |
|
86 | | -Note: You can use your favorite IDE to build solution. |
87 | | -Tested Visual Studio and Rider on Windows and Rider on Mac. |
| 46 | +Note: Alternatively you can build with your favorite IDE. This was tested with Visual Studio and Rider on Windows and Rider on Mac. |
| 47 | + |
| 48 | +See the documentation page for the [command line tool](./UnityDataTool/README.md) for information about how to run the tool after you have built it. |
| 49 | + |
| 50 | +## What is the purpose of the UnityFileSystemApi native library? |
| 51 | + |
| 52 | +The purpose of the UnityFileSystemApi is to expose the functionalities of the WebExtract and |
| 53 | +binary2text tools, but in a more flexible way. |
| 54 | + |
| 55 | +To better understand the files and data formats that the Unity supports in the runtime see [this topic](./Documentation/unity-content-format.md). |
| 56 | + |
| 57 | +## Origins |
| 58 | + |
| 59 | +This tool is the evolution of the [AssetBundle Analyzer](https://github.com/faelenor/asset-bundle-analyzer) |
| 60 | +written by [Francis Pagé](https://www.github.com/faelenor). |
| 61 | + |
| 62 | +That project was the first to introduce the SQLite database analysis of Unity build output to address |
| 63 | +the difficulty of diagnosing build issues through the raw binary2text output, which is large and difficult to navigate. |
| 64 | + |
| 65 | +The AssetBundle Analyzer was quite successful, but it has several issues. It |
| 66 | +is extremely slow as it runs WebExtract and binary2text on all the AssetBundles of a project and |
| 67 | +has to parse very large text files. It can also easily fail because the syntax used by binary2text |
| 68 | +is not standard and can even be impossible to parse in some occasions. |
| 69 | + |
| 70 | +To address those problems [@faelenor](https://www.github.com/faelenor) established this UnityDataTools |
| 71 | +repository and the UnityFileSystemApi library was created within Unity, to replace the usage of WebExtract and |
| 72 | +binary2text functionalities. With the library, it becomes very easy to create a binary2text-like tool |
| 73 | +that can output the data in any format, as well as the fast and simpler code for generating the SQLite output. |
| 74 | + |
| 75 | +This tool continues to be useful in recent Unity versions, for example Unity 6. |
88 | 76 |
|
89 | 77 | ## Disclaimer |
| 78 | + |
90 | 79 | This project is provided on an "as-is" basis and is not officially supported by Unity. It is an |
91 | 80 | experimental tool provided as an example of what can be done using the UnityFileSystemApi. You can |
92 | 81 | report bugs and submit pull requests, but there is no guarantee that they will be addressed. |
93 | | - |
94 | | ---- |
95 | | -*Footnotes*: <a name="footnote1">1</a>: AssetBundles include the TypeTree by default but this can |
96 | | - be disabled by using the |
97 | | - [DisableWriteTypeTree](https://docs.unity3d.com/ScriptReference/BuildAssetBundleOptions.DisableWriteTypeTree.html) |
98 | | - option. |
0 commit comments