using System; using System.Runtime.InteropServices; namespace UnityEngine.XR.ARSubsystems { /// /// Contains low-level data for a tracked image in the environment. /// [StructLayout(LayoutKind.Sequential)] public struct XRTrackedImage : ITrackable, IEquatable { /// /// Constructs an . /// /// The associated with this tracked image. /// A GUID associated with the source image. /// The Pose associated with the detected image. /// The size (dimensions) of the detected image. /// The of the detected image. /// A native pointer associated with the detected image. public XRTrackedImage( TrackableId trackableId, Guid sourceImageId, Pose pose, Vector2 size, TrackingState trackingState, IntPtr nativePtr) { m_Id = trackableId; m_SourceImageId = sourceImageId; m_Pose = pose; m_Size = size; m_TrackingState = trackingState; m_NativePtr = nativePtr; } /// /// Generates a populated with default values. /// public static XRTrackedImage defaultValue => s_Default; static readonly XRTrackedImage s_Default = new XRTrackedImage { m_Id = TrackableId.invalidId, m_SourceImageId = Guid.Empty, m_Pose = Pose.identity, }; /// /// The associated with this tracked image. /// public TrackableId trackableId => m_Id; /// /// The GUID associated with the source image. /// public Guid sourceImageId => m_SourceImageId; /// /// The Pose associated with this tracked image. /// public Pose pose => m_Pose; /// /// The size (dimensions) of this tracked image. /// public Vector2 size => m_Size; /// /// The associated with this tracked image. /// public TrackingState trackingState => m_TrackingState; /// /// A native pointer associated with this tracked image. /// The data pointed to by this pointer is implementation-defined. /// While its lifetime is also implementation-defined, it should be /// valid at least until the next call to /// . /// public IntPtr nativePtr => m_NativePtr; /// /// Generates a hash suitable for use with containers like `HashSet` and `Dictionary`. /// /// A hash code generated from this object's fields. public override int GetHashCode() { unchecked { var hashCode = m_Id.GetHashCode(); hashCode = hashCode * 486187739 + m_SourceImageId.GetHashCode(); hashCode = hashCode * 486187739 + m_Pose.GetHashCode(); hashCode = hashCode * 486187739 + m_Size.GetHashCode(); hashCode = hashCode * 486187739 + ((int)m_TrackingState).GetHashCode(); return hashCode; } } /// /// Tests for equality. /// /// The other to compare against. /// `True` if every field in is equal to this , otherwise false. public bool Equals(XRTrackedImage other) { return m_Id.Equals(other.m_Id) && m_SourceImageId.Equals(other.m_SourceImageId) && m_Pose.Equals(other.m_Pose) && m_Size.Equals(other.m_Size) && m_TrackingState == other.m_TrackingState; } /// /// 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 XRTrackedImage && Equals((XRTrackedImage)obj); /// /// 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==(XRTrackedImage lhs, XRTrackedImage 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!=(XRTrackedImage lhs, XRTrackedImage rhs) => !lhs.Equals(rhs); TrackableId m_Id; Guid m_SourceImageId; Pose m_Pose; Vector2 m_Size; TrackingState m_TrackingState; IntPtr m_NativePtr; } }