using System; using Newtonsoft.Json; namespace Unity.Pipeline.Models { /// /// Agent-supplied handle that references an existing Unity object — an asset or a /// loaded/scene object. Supply ONE form; /// tries them in order: globalId, path, guid (+ optional fileId), instanceId, hierarchyPath. /// [Serializable] [JsonConverter(typeof(ObjectRefConverter))] public class ObjectRef { /// Canonical GlobalObjectId string (addresses assets and scene objects uniformly). [JsonProperty("globalId")] public string GlobalId { get; set; } /// Project-relative asset path, e.g. "Assets/Foo/Bar.prefab". [JsonProperty("path")] public string Path { get; set; } /// Asset GUID. [JsonProperty("guid")] public string Guid { get; set; } /// Local file id, used with to address a sub-asset. [JsonProperty("fileId")] public long? FileId { get; set; } /// Instance id of a loaded/scene object. [JsonProperty("instanceId")] public ObjectId? InstanceId { get; set; } /// Scene hierarchy path, e.g. "/Root/Child/Leaf". [JsonProperty("hierarchyPath")] public string HierarchyPath { get; set; } [JsonIgnore] public bool IsEmpty => string.IsNullOrEmpty(GlobalId) && string.IsNullOrEmpty(Path) && string.IsNullOrEmpty(Guid) && InstanceId == null && string.IsNullOrEmpty(HierarchyPath); public override string ToString() { if (!string.IsNullOrEmpty(GlobalId)) return GlobalId; if (!string.IsNullOrEmpty(Path)) return Path; if (!string.IsNullOrEmpty(Guid)) return FileId.HasValue ? $"guid:{Guid}:{FileId}" : $"guid:{Guid}"; if (InstanceId.HasValue) return $"instanceId:{InstanceId}"; if (!string.IsNullOrEmpty(HierarchyPath)) return HierarchyPath; return ""; } } }