Skip to content

Commit a3bff47

Browse files
committed
Added table with asset dependencies
1 parent 8d84985 commit a3bff47

38 files changed

+73945
-69759
lines changed

Analyzer.Tests/ExpectedData/2019.4.0f1/ExpectedValues.json

Lines changed: 806 additions & 24 deletions
Large diffs are not rendered by default.

Analyzer.Tests/ExpectedData/2020.3.0f1/ExpectedValues.json

Lines changed: 806 additions & 24 deletions
Large diffs are not rendered by default.

Analyzer.Tests/ExpectedData/2021.3.0f1/ExpectedValues.json

Lines changed: 806 additions & 24 deletions
Large diffs are not rendered by default.

Analyzer.Tests/ExpectedData/2022.1.20f1/ExpectedValues.json

Lines changed: 806 additions & 24 deletions
Large diffs are not rendered by default.

Analyzer.Tests/ExpectedData/2023.1.0a16/ExpectedValues.json

Lines changed: 806 additions & 24 deletions
Large diffs are not rendered by default.

Analyzer/AnalyzerTool.cs

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Diagnostics;
34
using System.IO;
5+
using System.Linq;
6+
using UnityDataTools.Analyzer.SerializedObjects;
47
using UnityDataTools.Analyzer.SQLite;
58
using UnityDataTools.FileSystem;
9+
using UnityDataTools.FileSystem.TypeTreeReaders;
610

711
namespace UnityDataTools.Analyzer;
812

@@ -32,34 +36,48 @@ public int Analyze(string path, string databaseName, string searchPattern, bool
3236
{
3337
try
3438
{
39+
UnityArchive archive = null;
40+
3541
try
3642
{
37-
using var archive = UnityFileSystem.MountArchive(file, "/");
38-
var assetBundleName = Path.GetRelativePath(path, file);
43+
archive = UnityFileSystem.MountArchive(file, "/");
44+
}
45+
catch (NotSupportedException)
46+
{
47+
// It wasn't an AssetBundle, try to open the file as a SerializedFile.
3948

40-
writer.BeginAssetBundle(assetBundleName, new FileInfo(file).Length);
49+
var serializedFileName = Path.GetRelativePath(path, file);
4150

42-
var message = $"Processing { i * 100 / files.Length}% ({ i}/{ files.Length}) { assetBundleName}";
43-
Console.Write($"\r{message}{new string(' ', Math.Max(0, lastLength - message.Length))}");
44-
lastLength = message.Length;
51+
Console.Write($"\rProcessing {i * 100 / files.Length}% ({i}/{files.Length}) {file}");
4552

46-
foreach (var node in archive.Nodes)
53+
writer.WriteSerializedFile(serializedFileName, file);
54+
}
55+
56+
if (archive != null)
57+
{
58+
try
4759
{
48-
if (node.Flags.HasFlag(ArchiveNodeFlags.SerializedFile))
60+
var assetBundleName = Path.GetRelativePath(path, file);
61+
62+
writer.BeginAssetBundle(assetBundleName, new FileInfo(file).Length);
63+
64+
var message = $"Processing {i * 100 / files.Length}% ({i}/{files.Length}) {assetBundleName}";
65+
Console.Write($"\r{message}{new string(' ', Math.Max(0, lastLength - message.Length))}");
66+
lastLength = message.Length;
67+
68+
foreach (var node in archive.Nodes)
4969
{
50-
writer.WriteSerializedFile(node.Path, "/" + node.Path);
70+
if (node.Flags.HasFlag(ArchiveNodeFlags.SerializedFile))
71+
{
72+
writer.WriteSerializedFile(node.Path, "/" + node.Path);
73+
}
5174
}
5275
}
53-
54-
writer.EndAssetBundle();
55-
}
56-
catch (NotSupportedException)
57-
{
58-
var serializedFileName = Path.GetRelativePath(path, file);
59-
60-
Console.Write($"\rProcessing {i * 100 / files.Length}% ({i}/{files.Length}) {file}");
61-
62-
writer.WriteSerializedFile(serializedFileName, file);
76+
finally
77+
{
78+
writer.EndAssetBundle();
79+
archive.Dispose();
80+
}
6381
}
6482
}
6583
catch (Exception e)
@@ -85,4 +103,4 @@ public int Analyze(string path, string databaseName, string searchPattern, bool
85103

86104
return 0;
87105
}
88-
}
106+
}

Analyzer/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ that were automatically added by Unity at build time won't appear in this view.
7474
same as those in the *object_view* with the addition of the *asset_name* that contains the filename
7575
of the asset.
7676

77+
## asset_dependencies_view (AssetBundleProcessor)
78+
79+
This view lists the dependencies of all the assets. You can filter by id or asset_name to get all
80+
the dependencies of an asset. Conversely, filtering by dep_id will return all the assets that
81+
depend on this object. This can be useful to figure out why an asset was included in a build.
82+
7783
## animation_view (AnimationClipProcessor)
7884

7985
This provides additional information about AnimationClips. The columns are the same as those in

Analyzer/Resources/AssetBundle.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,19 @@
33
name TEXT
44
);
55

6+
CREATE TABLE asset_dependencies(
7+
object INTEGER,
8+
dependency INTEGER
9+
);
10+
611
CREATE VIEW asset_view AS
712
SELECT
813
a.name AS asset_name,
914
o.*
1015
FROM assets a INNER JOIN object_view o ON o.id = a.object;
16+
17+
CREATE VIEW asset_dependencies_view AS
18+
SELECT a.id, a.asset_name, a.asset_bundle, a.type, od.id dep_id, od.asset_bundle dep_asset_bundle, od.name dep_name, od.type dep_type
19+
FROM asset_view a
20+
INNER JOIN asset_dependencies d ON a.id = d.object
21+
INNER JOIN object_view od ON od.id = d.dependency;

Analyzer/Resources/Init.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,7 @@ INNER JOIN object_view t ON r.referenced_object = t.id
100100
LEFT JOIN assets a ON m.id = a.object
101101
WHERE m.type = "Material";
102102

103+
INSERT INTO types (id, name) VALUES (-1, 'Scene');
104+
103105
PRAGMA synchronous = OFF;
104106
PRAGMA journal_mode = MEMORY;

Analyzer/SQLite/Handlers/AnimationClipHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void Init(SQLiteConnection db)
2525
m_InsertCommand.Parameters.Add("@events", DbType.Int32);
2626
}
2727

28-
public void Process(ObjectIdProvider idProvider, long objectId, Dictionary<int, int> localToDbFileId, RandomAccessReader reader, out string name, out long streamDataSize)
28+
public void Process(Context ctx, long objectId, RandomAccessReader reader, out string name, out long streamDataSize)
2929
{
3030
var animationClip = AnimationClip.Read(reader);
3131

0 commit comments

Comments
 (0)