using System; using System.Runtime.InteropServices; namespace UnityEngine.XR.ARSubsystems { /// /// Describes a tracked object detected by the . /// /// /// Tracked objects are detected based on the contents of an /// which contains reference objects for which to scan. Each represents /// an which has been detected in the environment. /// /// /// [StructLayout(LayoutKind.Sequential)] public struct XRTrackedObject : ITrackable, IEquatable { /// /// A with appropriate default values. /// public static XRTrackedObject defaultValue => s_Default; /// /// The associated with this tracked object. /// public TrackableId trackableId => m_TrackableId; /// /// The Pose associated with this tracked object. /// public Pose pose => m_Pose; /// /// The associated with this tracked object. /// public TrackingState trackingState => m_TrackingState; /// /// A native pointer associated with this tracked object. /// /// /// The lifetime of this pointer is provider-specific, but /// should be valid at least until the next call to /// /// (typically once per frame). /// public IntPtr nativePtr => m_NativePtr; /// /// The GUID associated with the source . /// public Guid referenceObjectGuid => m_ReferenceObjectGuid; /// /// Constructs an . /// /// The associated with this tracked object. /// The Pose of this tracked object. /// The of the tracked object. /// A native pointer associated with this tracked object. If not null, /// the object pointed to by this pointer should be valid at least until the next call to /// . /// The GUID of the reference object which was used to detect this tracked object. public XRTrackedObject( TrackableId trackableId, Pose pose, TrackingState trackingState, IntPtr nativePtr, Guid referenceObjectGuid) { m_TrackableId = trackableId; m_Pose = pose; m_TrackingState = trackingState; m_NativePtr = nativePtr; m_ReferenceObjectGuid = referenceObjectGuid; } /// /// 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 XRTrackedObject other && Equals(other); /// /// Generates a hash suitable for use with containers like `HashSet` and `Dictionary`. /// /// A hash code generated from this object's . public override int GetHashCode() => m_TrackableId.GetHashCode(); /// /// 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 ==(XRTrackedObject lhs, XRTrackedObject 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 !=(XRTrackedObject lhs, XRTrackedObject rhs) => !lhs.Equals(rhs); /// /// Tests for equality. /// /// The other to compare against. /// `True` if this object's is equal to 's, otherwise false. public bool Equals(XRTrackedObject other) => m_TrackableId.Equals(other.m_TrackableId); TrackableId m_TrackableId; Pose m_Pose; TrackingState m_TrackingState; IntPtr m_NativePtr; Guid m_ReferenceObjectGuid; static readonly XRTrackedObject s_Default = new XRTrackedObject { m_TrackableId = TrackableId.invalidId, m_Pose = Pose.identity, m_ReferenceObjectGuid = Guid.Empty, }; } }