Skip to content

Commit 2d116a8

Browse files
WIP Attempt to support analysis of more than one build
If two versions of the same builds are in separate directories then we can potentially support analysis into a single DB by incorporating the path into the unique id generation. However so far this approach is breaking the asset dependency view, so either this approach is fundamentally flawed or a few more fixes could complete it. Even with this fix dependencies between AssetBundles are fundamentally not "1-1" if different AssetBundles have the same filenames and are in the same folder - we don't know which one to pick. This can be the case with AssetBundle variants or other cases where the game logic konws which AssetBundle to load at runtime and only one of the "conflicting" bundles will be loaded. How analyze should properly handle this case is TBD.
1 parent 26be265 commit 2d116a8

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

Analyzer/SQLite/SQLiteWriter.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,14 @@ public void WriteSerializedFile(string relativePath, string fullPath, string con
177177
using var sf = UnityFileSystem.OpenSerializedFile(fullPath);
178178
using var reader = new UnityFileReader(fullPath, 64 * 1024 * 1024);
179179
using var pptrReader = new PPtrAndCrcProcessor(sf, reader, containingFolder, AddReference);
180-
int serializedFileId = m_SerializedFileIdProvider.GetId(Path.GetFileName(fullPath).ToLower());
180+
181+
// Determine a unique id for this serialized file.
182+
// When processing AssetBundles the fullPath is a virtual path inside the AssetBundle.
183+
// Normally the serialized files have unique names across the output of an AssetBundle build.
184+
// But we mix in the containing folder in case analyze is being run on the output of more than one build.
185+
var uniquePath = $"{Path.GetFileName(fullPath).ToLower()}-{containingFolder}";
186+
int serializedFileId = m_SerializedFileIdProvider.GetId(uniquePath);
187+
181188
int sceneId = -1;
182189

183190
using var transaction = m_Database.BeginTransaction();
@@ -192,7 +199,8 @@ public void WriteSerializedFile(string relativePath, string fullPath, string con
192199
// There is no Scene object in Unity (a Scene is the full content of a
193200
// SerializedFile). We generate an object id using the name of the Scene
194201
// as SerializedFile name, and the object id 0.
195-
sceneId = m_ObjectIdProvider.GetId((m_SerializedFileIdProvider.GetId(sceneName), 0));
202+
string uniqueSceneName = $"{sceneName}-{containingFolder}";
203+
sceneId = m_ObjectIdProvider.GetId((m_SerializedFileIdProvider.GetId(uniqueSceneName), 0));
196204

197205
// There are 2 SerializedFiles per Scene, one ends with .sharedAssets. This is a
198206
// dirty trick to avoid inserting the scene object a second time.
@@ -239,8 +247,14 @@ public void WriteSerializedFile(string relativePath, string fullPath, string con
239247
m_LocalToDbFileId.Add(localId++, serializedFileId);
240248
foreach (var extRef in sf.ExternalReferences)
241249
{
242-
m_LocalToDbFileId.Add(localId++,
243-
m_SerializedFileIdProvider.GetId(extRef.Path.Substring(extRef.Path.LastIndexOf('/') + 1).ToLower()));
250+
// References inside an AssetBundle point to the SerializedFile, not the AssetBundle.
251+
// This works provided the AssetBundle is loaded, making the Serialized Files visible, and those
252+
// files are normally unique per build output.
253+
// To support analyzing multiple builds in different folders we mix in the containing folder to
254+
// generate the unique id. If multiple AssetBundles in the same folder have the same serialized file name
255+
// then the reference is ambiguous and there will be an SQL unique constraint exception.
256+
string uniqueExternalPath = $"{extRef.Path.Substring(extRef.Path.LastIndexOf('/') + 1).ToLower()}-{containingFolder}";
257+
m_LocalToDbFileId.Add(localId++, m_SerializedFileIdProvider.GetId(uniqueExternalPath));
244258
}
245259

246260
foreach (var obj in sf.Objects)

0 commit comments

Comments
 (0)