using System; using UnityEngine.SubsystemsImplementation; namespace UnityEngine.XR.ARSubsystems { /// /// Descriptor for the . Describes capabilities of a specific raycast provider. /// public sealed class XRRaycastSubsystemDescriptor : SubsystemDescriptorWithProvider { /// /// Used to register a descriptor. See . /// public struct Cinfo : IEquatable { /// /// A provider-specific identifier. /// public string id { get; set; } /// /// Specifies the provider implementation type to use for instantiation. /// /// /// The provider implementation type to use for instantiation. /// public Type providerType { get; set; } /// /// Specifies the XRAnchorSubsystem-derived type that forwards casted calls to its provider. /// /// /// The type of the subsystem to use for instantiation. If null, XRAnchorSubsystem will be instantiated. /// public Type subsystemTypeOverride { get; set; } /// /// The Type of the subsystem. /// [Obsolete("XRRaycastSubsystem no longer supports the deprecated set of base classes for subsystems as of Unity 2020.2. Use providerType and, optionally, subsystemTypeOverride instead.", true)] public Type subsystemImplementationType { get; set; } /// /// Whether the provider supports casting a ray from a screen point. /// public bool supportsViewportBasedRaycast { get; set; } /// /// Whether the provider supports casting an arbitrary ray. /// public bool supportsWorldBasedRaycast { get; set; } /// /// The types of trackables against which raycasting is supported. /// public TrackableType supportedTrackableTypes { get; set; } /// /// Whether tracked raycasts are supported. A tracked raycast is repeated /// over time and the results are updated automatically. /// public bool supportsTrackedRaycasts { get; set; } /// /// 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() => HashCodeUtil.Combine( HashCodeUtil.ReferenceHash(id), HashCodeUtil.ReferenceHash(providerType), HashCodeUtil.ReferenceHash(subsystemTypeOverride), supportsViewportBasedRaycast.GetHashCode(), supportsWorldBasedRaycast.GetHashCode(), ((int)supportedTrackableTypes).GetHashCode(), supportsTrackedRaycasts.GetHashCode()); /// /// 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 Cinfo) && Equals((Cinfo)obj); /// /// Generates a string representation of this . /// /// A string representation of this . public override string ToString() { return string.Format("XRRaycastSubsystemDescriptor:\nsupportsViewportBasedRaycast: {0}\nsupportsWorldBasedRaycast: {1}", supportsViewportBasedRaycast, supportsWorldBasedRaycast); } /// /// Tests for equality. /// /// The other to compare against. /// `True` if every field in is equal to this , otherwise false. public bool Equals(Cinfo other) { return String.Equals(id, other.id) && ReferenceEquals(providerType, other.providerType) && ReferenceEquals(subsystemTypeOverride, other.subsystemTypeOverride) && supportsViewportBasedRaycast == other.supportsViewportBasedRaycast && supportsWorldBasedRaycast == other.supportsWorldBasedRaycast && supportedTrackableTypes == other.supportedTrackableTypes; } /// /// 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 ==(Cinfo lhs, Cinfo rhs) { return 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 !=(Cinfo lhs, Cinfo rhs) { return !lhs.Equals(rhs); } } /// /// Whether the provider supports casting a ray from a screen point. /// public bool supportsViewportBasedRaycast { get; private set; } /// /// Whether the provider supports casting an arbitrary ray. /// public bool supportsWorldBasedRaycast { get; private set; } /// /// The types of trackables against which raycasting is supported. /// public TrackableType supportedTrackableTypes { get; private set; } /// /// Whether "tracked" raycasts are supported. A tracked raycast is repeated /// over time and the results are updated automatically. /// public bool supportsTrackedRaycasts { get; set; } /// /// Registers a new descriptor. Should be called by provider implementations. /// /// public static void RegisterDescriptor(Cinfo cinfo) { SubsystemDescriptorStore.RegisterDescriptor(new XRRaycastSubsystemDescriptor(cinfo)); } XRRaycastSubsystemDescriptor(Cinfo cinfo) { id = cinfo.id; providerType = cinfo.providerType; subsystemTypeOverride = cinfo.subsystemTypeOverride; supportsViewportBasedRaycast = cinfo.supportsViewportBasedRaycast; supportsWorldBasedRaycast = cinfo.supportsWorldBasedRaycast; supportedTrackableTypes = cinfo.supportedTrackableTypes; supportsTrackedRaycasts = cinfo.supportsTrackedRaycasts; } } }