using System;
using System.Runtime.InteropServices;
namespace UnityEngine.XR.ARSubsystems
{
///
/// Describes session-relative data for an anchor.
///
///
[StructLayout(LayoutKind.Sequential)]
public struct XRAnchor : ITrackable, IEquatable
{
///
/// Gets a default-initialized . This may be
/// different from the zero-initialized version (for example, the
/// is Pose.identity instead of zero-initialized).
///
public static XRAnchor defaultValue => s_Default;
static readonly XRAnchor s_Default = new XRAnchor
{
m_Id = TrackableId.invalidId,
m_Pose = Pose.identity,
m_SessionId = Guid.Empty
};
///
/// Constructs the session-relative data for an anchor.
/// This is typically provided by an implementation of the
/// and not invoked directly.
///
/// The associated with this anchor.
/// The Pose, in session space, of the anchor.
/// The of the anchor.
/// A native pointer associated with the anchor. The data pointed to by
/// this pointer is implementation-specific.
public XRAnchor(
TrackableId trackableId,
Pose pose,
TrackingState trackingState,
IntPtr nativePtr)
{
m_Id = trackableId;
m_Pose = pose;
m_TrackingState = trackingState;
m_NativePtr = nativePtr;
m_SessionId = Guid.Empty;
}
///
/// Constructs the session-relative data for anchor.
/// This is typically provided by an implementation of the
/// and not invoked directly.
///
/// The associated with this anchor.
/// The Pose, in session space, of the anchor.
/// The of the anchor.
/// A native pointer associated with the anchor. The data pointed to by
/// this pointer is implementation-specific.
/// The session from which this anchor originated.
public XRAnchor(
TrackableId trackableId,
Pose pose,
TrackingState trackingState,
IntPtr nativePtr,
Guid sessionId)
: this(trackableId, pose, trackingState, nativePtr)
{
m_SessionId = sessionId;
}
///
/// Get the associated with this anchor.
///
public TrackableId trackableId => m_Id;
///
/// Get the Pose, in session space, for this anchor.
///
public Pose pose => m_Pose;
///
/// Get the of this anchor.
///
public TrackingState trackingState => m_TrackingState;
///
/// A native pointer associated with the anchor.
/// The data pointed to by this pointer is implementation-specific.
///
public IntPtr nativePtr => m_NativePtr;
///
/// The id of the session from which this anchor originated.
///
public Guid sessionId => m_SessionId;
///
/// 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_Pose.GetHashCode();
hashCode = hashCode * 486187739 + ((int)m_TrackingState).GetHashCode();
hashCode = hashCode * 486187739 + m_NativePtr.GetHashCode();
hashCode = hashCode * 486187739 + m_SessionId.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(XRAnchor other)
{
return
m_Id.Equals(other.m_Id) &&
m_Pose.Equals(other.m_Pose) &&
m_TrackingState == other.m_TrackingState &&
m_NativePtr == other.m_NativePtr &&
m_SessionId.Equals(other.m_SessionId);
}
///
/// 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 XRAnchor && Equals((XRAnchor)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==(XRAnchor lhs, XRAnchor 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!=(XRAnchor lhs, XRAnchor rhs) => !lhs.Equals(rhs);
TrackableId m_Id;
Pose m_Pose;
TrackingState m_TrackingState;
IntPtr m_NativePtr;
Guid m_SessionId;
}
}