using System; using UnityEngine.SubsystemsImplementation; namespace UnityEngine.XR.ARSubsystems { /// /// The descriptor of the that shows which depth detection features are available on that XRSubsystem. /// /// /// Use the factory method along with struct to construct and /// register one of these from each depth data provider. /// /// public class XRDepthSubsystemDescriptor : SubsystemDescriptorWithProvider { /// /// Describes the capabilities of an . /// [Flags] public enum Capabilities { /// /// The subsystem does not support any capabilities. /// None = 0, /// /// The subsystem supports feature points (point cloud). /// FeaturePoints = 1 << 0, /// /// The subsystem supports a confidence value for each feature point. /// Confidence = 1 << 1, /// /// The subsystem provides unique identifiers for each feature point. /// UniqueIds = 1 << 2 } /// /// This struct is an initializer for the creation of a . /// /// /// Depth data provider should create a descriptor during InitializeOnLoad using /// the parameters here to specify which of the XRDepthSubsystem features it supports. /// public struct Cinfo : IEquatable { /// /// The string identifier for a specific implementation. /// public string id; /// /// Specifies the provider implementation type to use for instantiation. /// /// /// The provider implementation type to use for instantiation. /// public Type providerType { get; set; } /// /// Specifies the XRDepthSubsystem-derived type that forwards casted calls to its provider. /// /// /// The type of the subsystem to use for instantiation. If null, XRDepthSubsystem will be instantiated. /// public Type subsystemTypeOverride { get; set; } /// /// The concrete Type which will be instantiated if Create is called on this subsystem descriptor. /// [Obsolete("XRDepthSubsystem 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 implementationType; /// /// True if the subsystem supports feature points, false otherwise. /// public bool supportsFeaturePoints { get => (capabilities & Capabilities.FeaturePoints) != 0; set { if (value) { capabilities |= Capabilities.FeaturePoints; } else { capabilities &= ~Capabilities.FeaturePoints; } } } /// /// True if the subsystem supports per feature point confidence values, false otherwise. /// public bool supportsConfidence { get => (capabilities & Capabilities.Confidence) != 0; set { if (value) { capabilities |= Capabilities.Confidence; } else { capabilities &= ~Capabilities.Confidence; } } } /// /// True if the subsystem supports per-feature point identifiers, false otherwise. /// public bool supportsUniqueIds { get => (capabilities & Capabilities.UniqueIds) != 0; set { if (value) { capabilities |= Capabilities.UniqueIds; } else { capabilities &= ~Capabilities.UniqueIds; } } } /// /// The capabilities of the subsystem implementation. /// Capabilities capabilities { get; set; } /// /// 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 capabilities == other.capabilities && id == other.id && providerType == other.providerType && subsystemTypeOverride == other.subsystemTypeOverride; } /// /// 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 hash suitable for use with containers like `HashSet` and `Dictionary`. /// /// A hash code generated from this object's fields. public override int GetHashCode() { unchecked { int hashCode = HashCodeUtil.ReferenceHash(id); hashCode = 486187739 * hashCode + HashCodeUtil.ReferenceHash(providerType); hashCode = 486187739 * hashCode + HashCodeUtil.ReferenceHash(subsystemTypeOverride); hashCode = 486187739 * hashCode + ((int)capabilities).GetHashCode(); return hashCode; } } /// /// 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) => 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) => !lhs.Equals(rhs); } XRDepthSubsystemDescriptor(Cinfo descriptorParams) { id = descriptorParams.id; providerType = descriptorParams.providerType; subsystemTypeOverride = descriptorParams.subsystemTypeOverride; supportsFeaturePoints = descriptorParams.supportsFeaturePoints; supportsUniqueIds = descriptorParams.supportsUniqueIds; supportsConfidence = descriptorParams.supportsConfidence; } /// /// True if the implementation supports feature points, false otherwise. /// public bool supportsFeaturePoints { get; private set; } /// /// True if the implementation supports per feature point identifiers, false otherwise. /// public bool supportsUniqueIds { get; private set; } /// /// True if the implementation supports per feature point confidence values, false otherwise. /// public bool supportsConfidence { get; private set; } /// /// Registers a subsystem implementation with the SubsystemManager. /// /// public static void RegisterDescriptor(Cinfo descriptorParams) { var descriptor = new XRDepthSubsystemDescriptor(descriptorParams); SubsystemDescriptorStore.RegisterDescriptor(descriptor); } } }