using System; using System.Runtime.InteropServices; namespace UnityEngine.XR.ARSubsystems { /// /// Represents the intersection of a raycast with a trackable. /// [StructLayout(LayoutKind.Sequential)] public struct XRRaycast : ITrackable, IEquatable { static readonly XRRaycast s_Default = new XRRaycast( TrackableId.invalidId, Pose.identity, TrackingState.None, IntPtr.Zero, 0, TrackableId.invalidId); /// /// A default-initialized raycast. /// This can be different from a zero-initialized raycast. /// public static XRRaycast defaultValue => s_Default; /// /// A unique identifier for this raycast. /// public TrackableId trackableId => m_TrackableId; /// /// The session-space Pose of this raycast's intersection with a target. /// public Pose pose => m_Pose; /// /// The of this raycast. /// public TrackingState trackingState => m_TrackingState; /// /// The pointer associated with this raycast. The data this pointer points to is implementation-defined. /// Refer to the platform-specific AR package for details. /// public IntPtr nativePtr => m_NativePtr; /// /// The session-space distance from the raycast origin to the intersection point. /// public float distance => m_Distance; /// /// The of the trackable hit by this raycast, or /// if none. /// public TrackableId hitTrackableId => m_HitTrackableId; /// /// Constructs an . /// /// The of the trackable which was hit. /// The session-space Pose of the intersection. /// The tracking state of this raycast. /// A pointer into native memory for this raycast. /// The session-space distance from the raycast origin to the intersection point. /// The of the trackable hit by this raycast, /// or if none. public XRRaycast( TrackableId trackableId, Pose pose, TrackingState trackingState, IntPtr nativePtr, float distance, TrackableId hitTrackableId) { m_TrackableId = trackableId; m_Pose = pose; m_TrackingState = trackingState; m_NativePtr = nativePtr; m_Distance = distance; m_HitTrackableId = hitTrackableId; } /// /// Computes a hash suitable for use in a `Dictionary` or `HashSet`. /// /// A hash code computed from this raycast's fields. public override int GetHashCode() { unchecked { var hash = m_TrackableId.GetHashCode(); hash = hash * 486187739 + m_Pose.GetHashCode(); hash = hash * 486187739 + ((int)m_TrackingState).GetHashCode(); hash = hash * 486187739 + m_NativePtr.GetHashCode(); hash = hash * 486187739 + m_Distance.GetHashCode(); hash = hash * 486187739 + m_HitTrackableId.GetHashCode(); return hash; } } /// /// Compares this raycast for equality with an `object`. /// /// The object to compare for equality. /// `True` if is a and compares . public override bool Equals(object obj) => (obj is XRRaycast) && Equals((XRRaycast)obj); /// /// Compares this raycast for equality with another raycast. /// /// The raycast with which to compare. /// `True` if all fields of both raycasts are equal. Otherwise, `false`. public bool Equals(XRRaycast other) => m_TrackableId.Equals(other.m_TrackableId) && m_Pose.Equals(other.m_Pose) && (m_TrackingState == other.m_TrackingState) && (m_NativePtr == other.m_NativePtr) && m_HitTrackableId.Equals(other.m_HitTrackableId) && m_Distance.Equals(other.m_Distance); /// /// Tests for equality between two s. Same as .Equals() /// /// The left-hand side of the comparison. /// The right-hand side of the comparison. /// `True` if all fields of both and are equal. public static bool operator ==(XRRaycast lhs, XRRaycast rhs) => lhs.Equals(rhs); /// /// Tests for inequality between two s. Same as !.Equals() /// /// The left-hand side of the comparison. /// The right-hand side of the comparison. /// `True` if any of the fields of and are not equal. public static bool operator !=(XRRaycast lhs, XRRaycast rhs) => !lhs.Equals(rhs); TrackableId m_TrackableId; Pose m_Pose; TrackingState m_TrackingState; IntPtr m_NativePtr; float m_Distance; TrackableId m_HitTrackableId; } }