Skip to content

Commit 88f8c2f

Browse files
Address github copilot code review comments
And other comment/doc improvements.
1 parent 2473341 commit 88f8c2f

4 files changed

Lines changed: 51 additions & 24 deletions

File tree

Analyzer.Tests/FileDetectionTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ public void TryParseMetadata_PlayerDataLevel0_ReturnsExpectedValues()
185185
Assert.IsNotNull(metadata);
186186

187187
// Verify exact values from the level0 metadata section.
188-
// This file was built with Unity 2022.1.20f1 for Windows Standalone (platform 2),
188+
// This file was built with Unity 2022.1.20f1 for StandaloneOSX (platform 2),
189189
// with TypeTrees enabled.
190190
Assert.That(metadata.UnityVersion, Is.EqualTo("2022.1.20f1"), "Unity version should be 2022.1.20f1");
191-
Assert.That(metadata.TargetPlatform, Is.EqualTo(2u), "Target platform should be 2 (Windows Standalone)");
191+
Assert.That(metadata.TargetPlatform, Is.EqualTo(2u), "Target platform should be 2 (StandaloneOSX)");
192192
Assert.IsTrue(metadata.EnableTypeTree, "EnableTypeTree should be true");
193193

194194
// --- TypeTree counts ---

Analyzer/Util/SerializedFileDetector.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ public class SerializedFileInfo
2222
///
2323
/// Each entry corresponds to one element of either the regular type list (m_Types) or the
2424
/// SerializeReference type list (m_RefTypes, version >= 20). Fields that are not applicable
25-
/// for a given entry use well-defined sentinel values rather than null:
25+
/// for a given entry use well-defined sentinel values:
2626
/// - UnityHash128 fields use IsZero == true to indicate "not present"
2727
/// - short ScriptTypeIndex uses -1 to indicate "not a script type"
2828
/// - string fields (ClassName, Namespace, AssemblyName) use string.Empty for regular type entries
29-
/// - TypeDependencies uses an empty array for ref type entries or version < 21
29+
/// - TypeDependencies uses an empty array for ref type entries or version < 21
3030
/// </summary>
3131
public class TypeTreeInfo
3232
{
@@ -36,15 +36,16 @@ public class TypeTreeInfo
3636

3737
/// <summary>
3838
/// Unity ClassID for this type (e.g. 114 = MonoBehaviour, 115 = MonoScript).
39-
/// Corresponds to m_PersistentTypeID in the file. For ref type entries this is
40-
/// typically 0 and less meaningful than ClassName/Namespace/AssemblyName.
39+
/// Corresponds to m_PersistentTypeID in the file. For ref type entries this is -1
40+
/// and the type is identified by the ClassName/Namespace/AssemblyName triple instead.
4141
/// </summary>
4242
public int PersistentTypeID { get; set; }
4343

4444
/// <summary>
45-
/// True if this type is stripped: no TypeTree blob is present and the object data
46-
/// cannot be fully deserialized without a matching runtime.
45+
/// True for types that represent Prefab-stripped objects. In text/YAML files this corresponds to the stripped keyword:
46+
/// e.g. --- !u!123 &111 stripped.
4747
/// </summary>
48+
/// <remarks>This field is not related to the presence of a TypeTree blob in the file.</remarks>
4849
public bool IsStrippedType { get; set; }
4950

5051
/// <summary>
@@ -78,22 +79,23 @@ public class TypeTreeInfo
7879
/// <summary>
7980
/// XXH3 content hash of the TypeTree blob. Stored explicitly in the metadata for
8081
/// version >= 23 (kExtractedTypeTreeSupport). IsZero == true indicates this field
81-
/// was not present in the metadata (version &lt; 23 or no inline TypeTree).
82+
/// was not present in the metadata (version < 23 or no inline TypeTree).
8283
/// </summary>
8384
public UnityHash128 TypeTreeContentHash { get; set; }
8485

8586
/// <summary>
8687
/// Actual size in bytes of the TypeTree blob for this entry.
8788
/// 0 when InlineTypeTree is false (stripped, EnableTypeTree=false, or extracted to
88-
/// an external store in version >= 23). For version &lt; 23 where the size is not
89+
/// an external store in version >= 23). For version < 23 where the size is not
8990
/// stored explicitly, this is computed by skipping over the blob during parsing.
9091
/// </summary>
9192
public uint TypeTreeSerializedSize { get; set; }
9293

9394
/// <summary>
9495
/// True when the TypeTree blob is present inline in this file's metadata and can be
95-
/// read without an external TypeTree store. False when stripped, EnableTypeTree is
96-
/// false, or TypeTreeSerializedSize is 0 (extracted, version >= 23).
96+
/// read without an external TypeTree store. False when EnableTypeTree is false, or
97+
/// TypeTreeSerializedSize is 0 (blob extracted to an external store, version >= 23).
98+
/// Note: IsStrippedType is orthogonal and does not affect TypeTree presence.
9799
/// </summary>
98100
public bool InlineTypeTree { get; set; }
99101

@@ -128,7 +130,7 @@ public class TypeTreeInfo
128130
/// <summary>
129131
/// Indices into the SerializedReferenceTypeTrees array representing the
130132
/// SerializeReference types that objects of this type may reference.
131-
/// Empty array for ref type entries or files with version &lt; 21.
133+
/// Empty array for ref type entries or files with version < 21.
132134
/// </summary>
133135
public int[] TypeDependencies { get; set; } = Array.Empty<int>();
134136
}
@@ -150,7 +152,7 @@ public class SerializedFileMetadata
150152

151153
/// <summary>
152154
/// Number of SerializeReference TypeTree entries (m_RefTypes).
153-
/// Always 0 for files with version &lt; 20 (kSupportsRefObject).
155+
/// Always 0 for files with version < 20 (kSupportsRefObject).
154156
/// </summary>
155157
public int SerializedReferenceTypeTreeCount { get; set; }
156158

@@ -161,7 +163,7 @@ public class SerializedFileMetadata
161163

162164
/// <summary>
163165
/// Summary of each SerializeReference type entry.
164-
/// Empty array for files with version &lt; 20.
166+
/// Empty array for files with version < 20.
165167
/// </summary>
166168
public TypeTreeInfo[] SerializedReferenceTypeTrees { get; set; }
167169
}
@@ -641,7 +643,7 @@ private static void ParseTypeTreeMetadata(BinaryReader reader, SerializedFileInf
641643
/// if version >= 23:
642644
/// [Hash128 typeTreeContentHash]
643645
/// [uint32 typeTreeSize] (0 = blob extracted to external store)
644-
/// [TypeTree blob] (present when version &lt; 23 or typeTreeSize > 0)
646+
/// [TypeTree blob] (present when version < 23 or typeTreeSize > 0)
645647
/// if version >= 21:
646648
/// if isRefType: [string className] [string nameSpace] [string asmName]
647649
/// else: [int32 depCount] [int32 * depCount]

Documentation/command-serialized-file.md

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,36 @@ Each element of `typeTrees` and `serializedReferenceTypeTrees` contains per-type
261261

262262
### Metadata Fields
263263

264-
| Field | Description |
265-
|-------|-------------|
266-
| **Unity Version** | The Unity version string used to build this file (e.g. `"2022.1.20f1"`, `"6000.0.65f1"`). |
267-
| **Target Platform** | Numeric platform identifier. Common values: `2` = OSX Standalone, `9` = iOS, `13` = Android, `19` = Windows Standalone x64. See [BuildTarget](https://docs.unity3d.com/ScriptReference/BuildTarget.html) for details. |
268-
| **TypeTree Definitions** | Whether the definition of the types are embedded in the file. `Inline` in Editor and TypeTree-enabled builds. `No` in Player builds with TypeTrees stripped (the default). TypeTrees are required for the `objectlist` and `externalrefs` subcommands to show type names. `External` when the TypeTrees are in an external shared file. |
269-
| **TypeTree Count** | Number of TypeTrees defined in the file. Each TypeTree corresponds to a unique type used by objects in the file. This array is present even when TypeTree definitions are not stored inline. |
270-
| **RefType Count** | Number of TypeTrees for SerializeReference classes saved in the file. |
264+
The text and JSON outputs use different field names and representations for some fields.
265+
266+
| Text Field | JSON Field | Description |
267+
|------------|------------|-------------|
268+
| **Unity Version** | `unityVersion` | The Unity version string used to build this file (e.g. `"2022.1.20f1"`, `"6000.0.65f1"`). |
269+
| **Target Platform** | `targetPlatform` | Numeric platform identifier. Common values: `2` = OSX Standalone, `9` = iOS, `13` = Android, `19` = Windows Standalone x64. See [BuildTarget](https://docs.unity3d.com/ScriptReference/BuildTarget.html) for details. |
270+
| **TypeTree Definitions** | `enableTypeTree` | Whether TypeTree blobs are stored in this file. The text output derives a descriptive string from the raw boolean and the parsed type entries; the JSON output exposes the raw boolean directly. Text values: `No` — TypeTrees absent (default Player build); `Inline` — all TypeTree blobs are embedded in the file (Editor and TypeTree-enabled builds); `External` — TypeTree blobs were extracted to a separate store (version ≥ 23); `Mixed` — entries disagree (unexpected; indicates a parser or file anomaly); `Unknown``enableTypeTree` is true but no type entries were parsed. TypeTrees are required for the `objectlist` and `externalrefs` subcommands to show type names. |
271+
| **TypeTree Count** | `typeTreeCount` | Number of regular (object) type entries recorded in the file. Present even when TypeTree definitions are not stored inline. |
272+
| **RefType Count** | `serializedReferenceTypeTreeCount` | Number of type entries for `[SerializeReference]` types recorded in the file. Always `0` for files with version < 20. |
273+
| *(JSON only)* | `typeTrees` | Array of per-type detail objects for the regular type entries. `null` when parsing failed or was not attempted. See **Per-Type Entry Fields** below. |
274+
| *(JSON only)* | `serializedReferenceTypeTrees` | Array of per-type detail objects for the `[SerializeReference]` type entries. Empty array for files with version < 20. See **Per-Type Entry Fields** below. |
275+
276+
### Per-Type Entry Fields
277+
278+
Each element of `typeTrees` and `serializedReferenceTypeTrees` in the JSON output contains the following fields:
279+
280+
| JSON Field | Description |
281+
|------------|-------------|
282+
| `persistentTypeID` | Unity ClassID (e.g. `114` = MonoBehaviour). `-1` for `[SerializeReference]` entries whose type has no built-in ClassID. |
283+
| `isStrippedType` | `true` for types representing prefab-stripped objects (the `stripped` keyword in YAML). Orthogonal to TypeTree presence. |
284+
| `scriptTypeIndex` | Index into the file's MonoScript reference list. `-1` for native Unity types. |
285+
| `scriptID` | 128-bit hash (MD4 of assembly + namespace + class name) identifying the MonoScript. All-zeros when not applicable. |
286+
| `oldTypeHash` | Hash of the TypeTree content as originally written; used for compatibility checking at load time. |
287+
| `typeTreeContentHash` | XXH3 hash of the TypeTree blob. All-zeros for files with version < 23. |
288+
| `typeTreeSerializedSize` | Byte size of the TypeTree blob for this entry. `0` when `inlineTypeTree` is false. |
289+
| `inlineTypeTree` | `true` when the TypeTree blob is present inline in the file's metadata. |
290+
| `className` | C# class name; non-empty only for `[SerializeReference]` entries (version ≥ 21). |
291+
| `namespaceName` | C# namespace; non-empty only for `[SerializeReference]` entries (version ≥ 21). |
292+
| `assemblyName` | Assembly name; non-empty only for `[SerializeReference]` entries (version ≥ 21). |
293+
| `typeDependencies` | Array of indices into `serializedReferenceTypeTrees` listing which `[SerializeReference]` types objects of this type may hold. Empty for `[SerializeReference]` entries or files with version < 21. |
271294

272295
Notes:
273296

UnityDataTool/SerializedFileCommands.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,10 @@ private static void OutputMetadataText(SerializedFileMetadata metadata)
254254
typeTreeDefinitions = "No";
255255
else if (metadata.TypeTrees == null || metadata.TypeTrees.Length == 0)
256256
typeTreeDefinitions = "Unknown";
257-
else if (metadata.TypeTrees[0].InlineTypeTree)
257+
else if (metadata.TypeTrees.All(t => t.InlineTypeTree))
258258
typeTreeDefinitions = "Inline";
259+
else if (metadata.TypeTrees.Any(t => t.InlineTypeTree))
260+
typeTreeDefinitions = "Mixed"; // unexpected: entries disagree on inline vs external
259261
else
260262
typeTreeDefinitions = "External";
261263

0 commit comments

Comments
 (0)