|
| 1 | +// This file defines the structure of the ContentLayout.json file produced by BuildPipeline.BuildContentDirectory |
| 2 | +// (available starting in Unity 6.6). |
| 3 | +// |
| 4 | +// See Documentation/contentlayout.md for further details. |
| 5 | +// |
| 6 | +// ContentLayout always represents the latest schema version (currently 1). If the schema changes |
| 7 | +// in future, older versions can be preserved under a version-specific namespace while this type |
| 8 | +// continues to track the latest version. |
| 9 | +namespace UnityDataTools.Models |
| 10 | +{ |
| 11 | + /// <summary> |
| 12 | + /// Category strings used by <see cref="BinaryArtifact.Category"/>. |
| 13 | + /// </summary> |
| 14 | + public static class BuildArtifactCategory |
| 15 | + { |
| 16 | + /// <summary>Texture data, written to a streaming resource (.resS) file.</summary> |
| 17 | + public const string Texture = "texture"; |
| 18 | + |
| 19 | + /// <summary>Mesh data, written to a streaming resource (.resS) file.</summary> |
| 20 | + public const string Mesh = "mesh"; |
| 21 | + |
| 22 | + /// <summary>Audio data, written to a resource (.resource) file.</summary> |
| 23 | + public const string Audio = "audio"; |
| 24 | + |
| 25 | + /// <summary>Video data, written to a resource (.resource) file.</summary> |
| 26 | + public const string Video = "video"; |
| 27 | + |
| 28 | + /// <summary>A SerializedFile / Content File (.cf).</summary> |
| 29 | + public const string ContentFile = "contentfile"; |
| 30 | + |
| 31 | + /// <summary>A manifest file (.json).</summary> |
| 32 | + public const string Manifest = "manifest"; |
| 33 | + } |
| 34 | + |
| 35 | + /// <summary> |
| 36 | + /// Describes a SerializedFile in the build output. |
| 37 | + /// </summary> |
| 38 | + public struct SerializedFileLayout |
| 39 | + { |
| 40 | + /// <summary>Index of this entry inside <see cref="ContentLayout.SerializedFiles"/>.</summary> |
| 41 | + public int Index; |
| 42 | + |
| 43 | + /// <summary>Stable identifier used to reference this SerializedFile from other SerializedFiles |
| 44 | + /// in a way that doesn't break when the content changes. Currently based on the cluster or guid of the source.</summary> |
| 45 | + public string ID; |
| 46 | + |
| 47 | + /// <summary>True for synthetic entries representing built-in Unity resources that are not produced |
| 48 | + /// by the build (currently only "Library/unity default resources"). Such entries have no ContentHash.</summary> |
| 49 | + public bool IsBuiltIn; |
| 50 | + |
| 51 | + /// <summary>The source assets included in this SerializedFile.</summary> |
| 52 | + public string[] SourceAssets; |
| 53 | + |
| 54 | + /// <summary>Indices into the containing <see cref="ContentLayout.SerializedFiles"/> array, identifying |
| 55 | + /// other SerializedFiles that need to be loaded prior to loading this SerializedFile.</summary> |
| 56 | + public int[] SerializedFileDependencies; |
| 57 | + |
| 58 | + /// <summary>ObjectIdHash values for loadable objects referenced from this SerializedFile.</summary> |
| 59 | + public string[] LoadableDependencies; |
| 60 | + |
| 61 | + /// <summary>Scene paths for scenes referenced from this SerializedFile.</summary> |
| 62 | + public string[] LoadableSceneDependencies; |
| 63 | + |
| 64 | + /// <summary>xxhash3 hash of the content, used for the filename (+".cf") and for lookup into UDS. |
| 65 | + /// Matches the <see cref="BinaryArtifact.ContentHash"/> of the corresponding entry in |
| 66 | + /// <see cref="ContentLayout.BinaryArtifacts"/>.</summary> |
| 67 | + public string ContentHash; |
| 68 | + } |
| 69 | + |
| 70 | + /// <summary> |
| 71 | + /// Records a loadable object in the build. Listed at the top level of the ContentLayout so that a |
| 72 | + /// loadable's identity is described independently of the SerializedFile that happens to contain it. |
| 73 | + /// </summary> |
| 74 | + public class LoadableObjectIdLayout |
| 75 | + { |
| 76 | + /// <summary>Hash of the GUID, LFID and IdentifierType.</summary> |
| 77 | + public string ObjectIdHash; |
| 78 | + |
| 79 | + /// <summary>AssetDatabase GUID of the source asset.</summary> |
| 80 | + public string GUID; |
| 81 | + |
| 82 | + /// <summary>Path of the source asset.</summary> |
| 83 | + public string AssetPath; |
| 84 | + |
| 85 | + /// <summary>Local file id of the source object.</summary> |
| 86 | + public long LFID; |
| 87 | + |
| 88 | + /// <summary>Identifier type of the source object.</summary> |
| 89 | + public int IdentifierType; |
| 90 | + |
| 91 | + /// <summary>Index into <see cref="ContentLayout.SerializedFiles"/> for the file that contains this |
| 92 | + /// loadable, or -1 if it was dropped (e.g. server build shader references).</summary> |
| 93 | + public int SerializedFile = -1; |
| 94 | + } |
| 95 | + |
| 96 | + /// <summary> |
| 97 | + /// Records a scene exposed as loadable in the build, and the SerializedFile that contains it. |
| 98 | + /// </summary> |
| 99 | + public class LoadableSceneIdLayout |
| 100 | + { |
| 101 | + /// <summary>AssetDatabase GUID of the scene.</summary> |
| 102 | + public string GUID; |
| 103 | + |
| 104 | + /// <summary>Scene path.</summary> |
| 105 | + public string Path; |
| 106 | + |
| 107 | + /// <summary>Index into <see cref="ContentLayout.SerializedFiles"/>, or -1 if not mapped.</summary> |
| 108 | + public int SerializedFile = -1; |
| 109 | + } |
| 110 | + |
| 111 | + /// <summary> |
| 112 | + /// Describes a binary artifact produced by the build (SerializedFile, streaming resource, manifest, etc.). |
| 113 | + /// </summary> |
| 114 | + public class BinaryArtifact |
| 115 | + { |
| 116 | + /// <summary>Index of this entry inside <see cref="ContentLayout.BinaryArtifacts"/>.</summary> |
| 117 | + public int Index; |
| 118 | + |
| 119 | + /// <summary>Content addressable hash. For ContentFile artifacts, the matching |
| 120 | + /// <see cref="SerializedFileLayout"/> can be found by ContentHash.</summary> |
| 121 | + public string ContentHash; |
| 122 | + |
| 123 | + /// <summary>One of the strings in <see cref="BuildArtifactCategory"/>.</summary> |
| 124 | + public string Category; |
| 125 | + |
| 126 | + /// <summary>Size in bytes.</summary> |
| 127 | + public ulong Size; |
| 128 | + |
| 129 | + /// <summary>Indices into <see cref="ContentLayout.BinaryArtifacts"/> identifying additional artifacts |
| 130 | + /// referenced from this one (e.g. mesh, audio). |
| 131 | + /// Note: this does not track references to other ContentFiles — those are recorded in |
| 132 | + /// <see cref="SerializedFileLayout.SerializedFileDependencies"/>.</summary> |
| 133 | + public int[] ArtifactReferences; |
| 134 | + |
| 135 | + /// <summary>The on-disk file extension for this artifact, derived from <see cref="Category"/>. |
| 136 | + /// For unrecognized categories, returns the category name.</summary> |
| 137 | + public string FileExtension |
| 138 | + { |
| 139 | + get |
| 140 | + { |
| 141 | + switch (Category) |
| 142 | + { |
| 143 | + case BuildArtifactCategory.Texture: |
| 144 | + case BuildArtifactCategory.Mesh: |
| 145 | + return ".resS"; |
| 146 | + case BuildArtifactCategory.Audio: |
| 147 | + case BuildArtifactCategory.Video: |
| 148 | + return ".resource"; |
| 149 | + case BuildArtifactCategory.ContentFile: |
| 150 | + return ".cf"; |
| 151 | + case BuildArtifactCategory.Manifest: |
| 152 | + return ".json"; |
| 153 | + default: |
| 154 | + return string.IsNullOrEmpty(Category) ? "" : "." + Category; |
| 155 | + } |
| 156 | + } |
| 157 | + } |
| 158 | + } |
| 159 | + |
| 160 | + /// <summary> |
| 161 | + /// In-memory representation of the ContentLayout.json file written by the build. |
| 162 | + /// |
| 163 | + /// The Layout is a companion to the BuildManifest, recording additional details about the build |
| 164 | + /// (including source assets and information about which object an ObjectId hash refers to). |
| 165 | + /// It is not shipped with the build; it exists for tools and tests that analyze build output. |
| 166 | + /// The schema is subject to change and there is currently no backward compatibility. |
| 167 | + /// </summary> |
| 168 | + public class ContentLayout |
| 169 | + { |
| 170 | + /// <summary>The schema version this type represents.</summary> |
| 171 | + public const int CurrentVersion = 1; |
| 172 | + |
| 173 | + /// <summary>Schema version of the ContentLayout.json file.</summary> |
| 174 | + public int Version; |
| 175 | + |
| 176 | + /// <summary>Hash of the BuildManifest this layout corresponds to.</summary> |
| 177 | + public string BuildManifestHash; |
| 178 | + |
| 179 | + /// <summary>The SerializedFiles in the build output.</summary> |
| 180 | + public SerializedFileLayout[] SerializedFiles; |
| 181 | + |
| 182 | + /// <summary>ObjectIdHash values of the root assets; resolve via <see cref="LoadableObjectIds"/>.</summary> |
| 183 | + public string[] RootAssets; |
| 184 | + |
| 185 | + /// <summary>Loadable objects in the build.</summary> |
| 186 | + public LoadableObjectIdLayout[] LoadableObjectIds; |
| 187 | + |
| 188 | + /// <summary>Loadable scenes in the build.</summary> |
| 189 | + public LoadableSceneIdLayout[] LoadableSceneIds; |
| 190 | + |
| 191 | + /// <summary>Binary artifacts produced by the build.</summary> |
| 192 | + public BinaryArtifact[] BinaryArtifacts; |
| 193 | + } |
| 194 | +} |
0 commit comments