using System;
using System.Runtime.InteropServices;
namespace UnityEngine.XR.ARSubsystems
{
///
/// The session-relative data associated with a 3D bounding box.
///
///
[StructLayout(LayoutKind.Sequential)]
public struct XRBoundingBox : ITrackable, IEquatable
{
///
/// The associated with this bounding box.
///
public TrackableId trackableId { get; }
///
/// The `Pose`, in session space, of the bounding box.
///
public Pose pose { get; }
///
/// The size (dimensions) of the bounding box in meters.
///
public Vector3 size { get; }
///
/// The of the bounding box.
///
public TrackingState trackingState { get; }
///
/// A native pointer associated with this bounding box.
/// The data pointed to by this pointer is implementation defined.
///
public IntPtr nativePtr { get; }
///
/// The classifications of this bounding box.
///
public BoundingBoxClassifications classifications { get; }
///
/// Constructs a new instance. `XRBoundingBox` objects are typically created by
/// XRBoundingBoxSubsystem.GetChanges.
///
/// The `TrackableId` associated with the bounding box.
/// The pose describing the position and orientation of the bounding box.
/// The dimensions of the bounding box.
/// The `TrackingState` describing how well the XR device is tracking the bounding box.
/// The BoundingBoxClassification assigned to the bounding box by the XR device.
/// The native pointer associated with the bounding box.
public XRBoundingBox(
TrackableId trackableId,
Pose pose,
Vector3 size,
TrackingState trackingState,
BoundingBoxClassifications classifications,
IntPtr nativePtr)
{
this.trackableId = trackableId;
this.pose = pose;
this.size = size;
this.trackingState = trackingState;
this.classifications = classifications;
this.nativePtr = nativePtr;
}
///
/// Generates a new string that describes the bounding box's properties, suitable for debugging purposes.
///
/// A string that describes the bounding box's properties.
public override string ToString()
{
SharedStringBuilder.stringBuilder.AppendLine("Bounding Box:");
SharedStringBuilder.stringBuilder.AppendLine("\ttrackableId: " + trackableId);
SharedStringBuilder.stringBuilder.AppendLine("\tpose: " + pose);
SharedStringBuilder.stringBuilder.AppendLine("\tsize: " + size);
SharedStringBuilder.stringBuilder.AppendLine("\tclassifications: " + classifications);
SharedStringBuilder.stringBuilder.AppendLine("\ttrackingState: " + trackingState);
SharedStringBuilder.stringBuilder.Append("\tnativePtr: ");
SharedStringBuilder.stringBuilder.Append("" + nativePtr.ToInt64(), 0, 16);
SharedStringBuilder.stringBuilder.Append("\n");
string tempString = SharedStringBuilder.stringBuilder.ToString();
SharedStringBuilder.stringBuilder.Clear();
return tempString;
}
///
/// 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 XRBoundingBox other) && Equals(other);
///
/// 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 = trackableId.GetHashCode();
hashCode = (hashCode * 486187739) + pose.GetHashCode();
hashCode = (hashCode * 486187739) + size.GetHashCode();
hashCode = (hashCode * 486187739) + ((int)classifications).GetHashCode();
hashCode = (hashCode * 486187739) + ((int)trackingState).GetHashCode();
hashCode = (hashCode * 486187739) + nativePtr.GetHashCode();
return hashCode;
}
}
///
/// Tests for equality. Equivalent to .
///
/// The left-hand side of the comparison.
/// The right-hand side of the comparison.
/// if is equal to . Otherwise, .
public static bool operator ==(XRBoundingBox lhs, XRBoundingBox rhs) => lhs.Equals(rhs);
///
/// Tests for inequality. Same as `!`.
///
/// The left-hand side of the comparison.
/// The right-hand side of the comparison.
/// if is not equal to , otherwise .
public static bool operator !=(XRBoundingBox lhs, XRBoundingBox rhs) => !lhs.Equals(rhs);
///
/// Tests for equality.
///
/// The other to compare against.
/// if every field in is equal to this , otherwise .
public bool Equals(XRBoundingBox other)
{
return
trackableId.Equals(other.trackableId) &&
pose.Equals(other.pose) &&
size.Equals(other.size) &&
(trackingState == other.trackingState) &&
(nativePtr == other.nativePtr) &&
(classifications == other.classifications);
}
}
}