Documentation

Unity Engine

Download Unity

Unity Engine

ContentFileIdentity

Identifies a content file of a content directory build, as listed in LoadedContentFileInfo.Identity.
Read time 2 minutesLast updated a day ago

Definition

public readonly struct ContentFileIdentity : IEquatable<ContentFileIdentity>

Remarks

A file has the same identity in every ContentLoadState of its content directory, so compare identities to follow a file from one state to the next. The same asset built into two content directories has the same identity in both.
ContentFileIdentity.ToString returns the file's
StableId
entry in the
ContentLayout.json
file of the build. Use it to find the file in that layout, for example to read the source assets of a file listed in a Player. Compare the string, do not parse it: its format belongs to the layout of the Unity version that made the build.
In the Editor, ContentLoadEditorUtility.TryGetSourceAssetGUID gives the asset that the file was built from.

Examples

using System;using System.Collections.Generic;using System.IO;using UnityEditor.Build;using UnityEngine;namespace BuildDocExamples{ // Example: name the files of a ContentDirectoryLoadInfo that a Player sent back. The Player sends // ContentDirectoryLoadInfo.BuildManifestHash and, for each file, ContentFileIdentity.ToString(). In // the Editor, the hash finds the build in this project's build history, and each identity is the // StableId of one entry of that build's ContentLayout.json file. public static class ContentDirectoryLoadInfo_BuildManifestHashExample { // The parts of ContentLayout.json that this example reads. [Serializable] class ContentLayout { public SerializedFile[] SerializedFiles; } [Serializable] class SerializedFile { public string StableId; public string[] SourceAssets; } public static void LogSourceAssets(Hash128 buildManifestHash, IEnumerable<string> fileIdentities) { if (!BuildHistory.TryGetBuildSummaryForManifestHash(buildManifestHash, out var summary) || !BuildHistory.TryGetFilePath(summary.BuildSessionGUID, "ContentLayout.json", out string layoutPath)) { Debug.LogWarning($"Build {buildManifestHash} is not in this project's build history."); return; } var layout = JsonUtility.FromJson<ContentLayout>(File.ReadAllText(layoutPath)); var sourceAssets = new Dictionary<string, string[]>(); foreach (SerializedFile file in layout.SerializedFiles) sourceAssets[file.StableId] = file.SourceAssets; foreach (string identity in fileIdentities) { // The paths are the ones the assets had when the content was built. string description = sourceAssets.TryGetValue(identity, out string[] assets) && assets.Length > 0 ? string.Join(", ", assets) : "no source asset"; Debug.Log($"{identity}: {description}"); } } }}

Properties

Property

Description

IsValidTrue if this identity names a content file.

Methods

Method

Description

ToStringReturns the
StableId
that the
ContentLayout.json
file of the build lists for this content file.