-
Notifications
You must be signed in to change notification settings - Fork 62
Restore "assets" table population and documentation tweaks #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
0347563
17ea8df
fc37354
3810f3d
f1c7630
b5351a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| using System; | ||
| using System.Text.RegularExpressions; | ||
| using Microsoft.Data.Sqlite; | ||
| using UnityDataTools.Analyzer.SerializedObjects; | ||
| using UnityDataTools.FileSystem.TypeTreeReaders; | ||
|
|
||
| namespace UnityDataTools.Analyzer.SQLite.Handlers; | ||
|
|
||
| public class AssetBundleHandler : ISQLiteHandler | ||
| { | ||
| SqliteCommand m_InsertCommand; | ||
| private SqliteCommand m_InsertDepCommand; | ||
| private Regex m_SceneNameRegex = new Regex(@"([^//]+)\.unity"); | ||
|
|
||
| public void Init(SqliteConnection db) | ||
| { | ||
| using var command = db.CreateCommand(); | ||
| command.CommandText = Resources.AssetBundle; | ||
| command.ExecuteNonQuery(); | ||
|
|
||
| m_InsertCommand = db.CreateCommand(); | ||
|
|
||
| m_InsertCommand.CommandText = "INSERT INTO assets(object, name) VALUES(@object, @name)"; | ||
| m_InsertCommand.Parameters.Add("@object", SqliteType.Integer); | ||
| m_InsertCommand.Parameters.Add("@name", SqliteType.Text); | ||
|
|
||
| m_InsertDepCommand = db.CreateCommand(); | ||
|
|
||
| m_InsertDepCommand.CommandText = "INSERT INTO asset_dependencies(object, dependency) VALUES(@object, @dependency)"; | ||
| m_InsertDepCommand.Parameters.Add("@object", SqliteType.Integer); | ||
| m_InsertDepCommand.Parameters.Add("@dependency", SqliteType.Integer); | ||
| } | ||
|
|
||
| public void Process(Context ctx, long objectId, RandomAccessReader reader, out string name, out long streamDataSize) | ||
| { | ||
| var assetBundle = AssetBundle.Read(reader); | ||
|
|
||
| foreach (var asset in assetBundle.Assets) | ||
| { | ||
| if (!assetBundle.IsSceneAssetBundle) | ||
| { | ||
| var fileId = ctx.LocalToDbFileId[asset.PPtr.FileId]; | ||
| var objId = ctx.ObjectIdProvider.GetId((fileId, asset.PPtr.PathId)); | ||
| m_InsertCommand.Transaction = ctx.Transaction; | ||
| m_InsertCommand.Parameters["@object"].Value = objId; | ||
| m_InsertCommand.Parameters["@name"].Value = asset.Name; | ||
| m_InsertCommand.ExecuteNonQuery(); | ||
|
|
||
| for (int i = asset.PreloadIndex; i < asset.PreloadIndex + asset.PreloadSize; ++i) | ||
| { | ||
| var dependency = assetBundle.PreloadTable[i]; | ||
| var depFileId = ctx.LocalToDbFileId[dependency.FileId]; | ||
| var depId = ctx.ObjectIdProvider.GetId((depFileId, dependency.PathId)); | ||
| m_InsertDepCommand.Transaction = ctx.Transaction; | ||
| m_InsertDepCommand.Parameters["@object"].Value = objId; | ||
| m_InsertDepCommand.Parameters["@dependency"].Value = depId; | ||
| m_InsertDepCommand.ExecuteNonQuery(); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| var match = m_SceneNameRegex.Match(asset.Name); | ||
|
|
||
| if (match.Success) | ||
| { | ||
| var sceneName = match.Groups[1].Value; | ||
| var objId = ctx.ObjectIdProvider.GetId((ctx.SerializedFileIdProvider.GetId(sceneName), 0)); | ||
| m_InsertCommand.Transaction = ctx.Transaction; | ||
| m_InsertCommand.Parameters["@object"].Value = objId; | ||
| m_InsertCommand.Parameters["@name"].Value = asset.Name; | ||
| m_InsertCommand.ExecuteNonQuery(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| name = assetBundle.Name; | ||
| streamDataSize = 0; | ||
| } | ||
|
|
||
| public void Finalize(SqliteConnection db) | ||
| { | ||
| using var command = new SqliteCommand(); | ||
| command.Connection = db; | ||
| command.CommandText = "CREATE INDEX asset_dependencies_object ON asset_dependencies(object)"; | ||
| command.ExecuteNonQuery(); | ||
|
|
||
| command.CommandText = "CREATE INDEX asset_dependencies_dependency ON asset_dependencies(dependency)"; | ||
| command.ExecuteNonQuery(); | ||
| } | ||
|
|
||
| void IDisposable.Dispose() | ||
| { | ||
| m_InsertCommand?.Dispose(); | ||
| m_InsertDepCommand?.Dispose(); | ||
| } | ||
| } | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Restored file, not new code |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,7 +64,7 @@ bool ShouldIgnoreFile(string file) | |
| private static readonly HashSet<string> IgnoredExtensions = new() | ||
| { | ||
| ".txt", ".resS", ".resource", ".json", ".dll", ".pdb", ".exe", ".manifest", ".entities", ".entityheader", | ||
| ".ini", ".config" | ||
| ".ini", ".config", ".hash" | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ignore .hash files - just to reduce the false alarm errors when parsing a "Library\com.unity.addressables" folder
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch. |
||
| }; | ||
|
|
||
| bool ProcessFile(string file, string rootDirectory) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ This topic gives some examples of using the SQLite output of the UnityDataTools | |
|
|
||
| The command line arguments to invoke Analyze are documented [here](../UnityDataTool/README.md#analyzeanalyse). | ||
|
|
||
| The definition of the views, and some internal details about how Analyze is implemented, can be found [here](../Analyzer/README.md). | ||
| The definition of the views, and some internal details about how Analyze is implemented, can be found [here](../Analyzer/README.md). | ||
|
|
||
| ## Running Queries from the Command line | ||
|
|
||
|
|
@@ -220,9 +220,13 @@ This is a large subject, see [Comparing Builds](comparing-builds.md). | |
|
|
||
| ## Example: Matching content back to the source asset | ||
|
|
||
| UnityDataTool works on the output of a Unity build, which, by its very nature, only contains the crucial data needed to efficiently load built content in the Player. So it does not include any information about the assets and scenes in the project that was used to create that build. However you may want to match content back to the original source asset or scene. For example if the size of an AssetBundle has unexpectedly changed between builds then you may want to track down which source assets could be responsible for that change. Or you may want to confirm that some particular image has been included in the build. | ||
| UnityDataTool works on the output of a Unity build, which, by its very nature, only contains the crucial data needed to efficiently load built content in the Player. It does not include complete information about the assets and scenes in the project that was used to create that build. You may want to match content back to the original source asset or scene. For example if the size of an AssetBundle has unexpectedly changed between builds then you may want to track down which source assets could be responsible for that change. Or you may want to confirm that some particular image has been included in the build. | ||
|
|
||
| In many cases the source asset can be inferred based on your specific knowledge of your project, and how the build was configured. For example the level files in a Player build match the Scenes in the Build Profile Scene list. And the content of AssetBundles is driven from the assignment of specific assets to those AssetBundles (or Addressable groups). | ||
| For AssetBundles partial asset information can be found in the m_Containers list, inside the AssetBundle object. This records assets that were explicitly added to AssetBundles. In the database this can be found in the `assets` table. However, asset that are included in the build implicitly (because they are referenced from the explicitly added assets) will not be recorded anywhere in the AssetBundle content. | ||
SkowronskiAndrew marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Similarly for a player build the only paths populated in the `assets` table are the scenes from the Build Profile Scene List. The paths of the assets in the sharedAsset files is not recorded anywhere in the build output. | ||
|
|
||
| In many cases the source asset can be inferred based on your specific knowledge of your project, and how the build was configured. For example the level files in a Player build match the Scenes in the Build Profile Scene list. And the content of AssetBundles is driven from the assignment of specific assets to those AssetBundles (or Addressable groups), along with assets they depend on. | ||
|
|
||
| Also, in many cases the name of objects matches the file name of the asset. For example the Texture2D "red" object probably comes from a file named red.png somewhere in the project. | ||
|
|
||
|
|
@@ -235,5 +239,4 @@ Examples of alternative sources of build information: | |
| * The [BuildReport](https://docs.unity3d.com/ScriptReference/Build.Reporting.BuildReport.html) has detailed source information in the PackedAssets section. The [BuildReportInspector](https://github.com/Unity-Technologies/BuildReportInspector) is a useful way to view data from the BuildReport. | ||
| * The Editor log reports a lot of information during a build. | ||
| * Regular AssetBundle builds create [.manifest files](https://docs.unity3d.com/Manual/assetbundles-file-format.html), which contain information about the source assets and types. | ||
| * Addressable builds do not produce BuildReport files, nor .manifest files. But there is similar reporting, for example the [Build Layout Report](https://docs.unity3d.com/Packages/com.unity.addressables@2.4/manual/BuildLayoutReport.html). | ||
|
|
||
| * Addressable builds do not produce BuildReport files, nor .manifest files. But UnityDataTools supports analyzing the [Addressables Build Reports](addressables-build-reports.md) and will populate the `addressables_build_explicit_assets` and `addressables_build_implicit_assets` tables. | ||
|
||
Uh oh!
There was an error while loading. Please reload this page.