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
/// can 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
{
///
/// Constructs a .
///
/// The [Guid](https://docs.microsoft.com/en-us/dotnet/api/system.guid?view=netframework-4.8)
/// associated with this image.
///
/// The [Guid](https://docs.microsoft.com/en-us/dotnet/api/system.guid?view=netframework-4.8)
/// of the source texture as it appeared in the
/// [AssetDatabase](https://docs.unity3d.com/ScriptReference/AssetDatabase.html)
/// in the Editor.
///
///
/// Optional. The size of the image, in meters. This can improve image detection,
/// and might be required by some platforms.
///
/// A name associated with this reference image.
///
/// The source texture which this reference image represents.
/// This can be `null` to avoid including the texture in
/// the Player build if you don't want that. See `XRReferenceImageLibraryExtensions.SetTexture`
/// for more details.
///
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](https://docs.microsoft.com/en-us/dotnet/api/system.guid?view=netframework-4.8)
/// associated with this image.
///
public Guid guid => m_SerializedGuid.guid;
///
/// The [Guid](https://docs.microsoft.com/en-us/dotnet/api/system.guid?view=netframework-4.8)
/// of the source texture as it appears 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 might 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 you don't want that. 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() =>
$"Name: '{name}', GUID: '{guid}', Texture GUID: '{textureGuid}` Size: {(m_SpecifySize ? "" : "NOT ")} specified {m_Size}";
///
/// Generates a hash suitable for use with containers like `HashSet` and `Dictionary`.
///
/// A hash code generated from this object's .
public override int GetHashCode() => guid.GetHashCode();
///
/// Tests for equality.
///
/// The `object` to compare against.
/// `True` if is of type and
/// also returns `true`; otherwise `false`.
public override bool Equals(object obj) => (obj is XRReferenceImage) && Equals((XRReferenceImage)obj);
///
/// Tests for equality.
///
/// The other to compare against.
/// `True` if the of this reference image matches 's, otherwise false.
public bool Equals(XRReferenceImage other) => guid.Equals(other.guid);
///
/// Tests for equality. Same as .
///
/// The left-hand side of the comparison.
/// The right-hand side of the comparison.
/// `True` if is equal to , otherwise `false`.
public static bool operator ==(XRReferenceImage lhs, XRReferenceImage rhs) => lhs.Equals(rhs);
///
/// Tests for inequality. Same as `!`.
///
/// The left-hand side of the comparison.
/// The right-hand side of the comparison.
/// `True` if is not equal to , otherwise `false`.
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
}
}