using System; namespace UnityEngine.XR.ARSubsystems { /// /// Represents an entry in an . /// /// /// A reference image is an image to look for in the physical environment. /// The does not directly reference a Texture2D /// or other image data; it only stores the GUID of the Texture2D as it /// appears in the AssetDatabase. At build time, platform specific build steps /// may use the guids to look up the source textures and generate an appropriate /// image database. At runtime, detected images can be matched up with the source /// . /// [Serializable] public struct XRReferenceImage : IEquatable { public XRReferenceImage( SerializableGuid guid, SerializableGuid textureGuid, Vector2? size, string name, Texture2D texture) { m_SerializedGuid = guid; m_SerializedTextureGuid = textureGuid; m_SpecifySize = size.HasValue; m_Size = size.HasValue ? size.Value : Vector2.zero; m_Name = name; m_Texture = texture; } /// /// The Guid associated with this image. /// public Guid guid => m_SerializedGuid.guid; /// /// The Guid of the source texture as it appeared in the /// [AssetDatabase](https://docs.unity3d.com/ScriptReference/AssetDatabase.html) /// in the Editor. /// public Guid textureGuid => m_SerializedTextureGuid.guid; /// /// Must be set to true for to be used. /// public bool specifySize => m_SpecifySize; /// /// The size of the image, in meters. This can improve image detection, /// and may be required by some platforms. /// public Vector2 size => m_Size; /// /// The width of the image, in meters. /// public float width => m_Size.x; /// /// The height of the image, in meters. /// public float height => m_Size.y; /// /// A name associated with this reference image. /// public string name => m_Name; /// /// The source texture which this reference image represents. /// This may be null to avoid including the texture in /// the Player build if that is not desired. See /// UnityEditor.XR.ARSubsystems.XRReferenceImageLibraryExtensions.SetTexture /// for more details. /// public Texture2D texture => m_Texture; /// /// Provides a string representation suitable for debug logging. /// /// A string representation of the reference image. public override string ToString() => $"GUID: '{guid}', Texture GUID: '{textureGuid}` Size: {(m_SpecifySize ? "" : "NOT ")} specified {m_Size}"; public override int GetHashCode() => guid.GetHashCode(); public override bool Equals(object obj) => (obj is XRReferenceImage) && Equals((XRReferenceImage)obj); public bool Equals(XRReferenceImage other) => guid.Equals(other.guid); public static bool operator ==(XRReferenceImage lhs, XRReferenceImage rhs) => lhs.Equals(rhs); public static bool operator !=(XRReferenceImage lhs, XRReferenceImage rhs) => !lhs.Equals(rhs); #pragma warning disable CS0649 [SerializeField] internal SerializableGuid m_SerializedGuid; [SerializeField] internal SerializableGuid m_SerializedTextureGuid; [SerializeField] internal Vector2 m_Size; [SerializeField] internal bool m_SpecifySize; [SerializeField] internal string m_Name; [SerializeField] internal Texture2D m_Texture; #pragma warning restore CS0649 } }