using System; using UnityEngine.SubsystemsImplementation; namespace UnityEngine.XR.ARSubsystems { /// /// Constructor parameters for the . /// public struct XROcclusionSubsystemCinfo : IEquatable { /// /// Specifies an identifier for the provider implementation of the subsystem. /// /// /// The identifier for the provider implementation of the subsystem. /// 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; } /// /// Specifies the provider implementation type to use for instantiation. /// /// /// Specifies the provider implementation type to use for instantiation. /// [Obsolete("XROcclusionSubsystem 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 { get; set; } /// /// Specifies if the current subsystem supports human segmentation stencil image. This property is deprecated. /// Use instead. /// /// /// true if the current subsystem supports human segmentation stencil image. Otherwise, false. /// [Obsolete("Use " + nameof(humanSegmentationStencilImageSupportedDelegate) + " instead.")] public bool supportsHumanSegmentationStencilImage { get; set; } /// /// Specifies whether a subsystem supports human segmentation stencil image. /// public Func humanSegmentationStencilImageSupportedDelegate { get; set; } /// /// Specifies if the current subsystem supports human segmentation depth image. This property is deprecated. /// Use instead. /// /// /// true if the current subsystem supports human segmentation depth image. Otherwise, false. /// [Obsolete("Use " + nameof(humanSegmentationDepthImageSupportedDelegate) + " instead.")] public bool supportsHumanSegmentationDepthImage { get; set; } /// /// Specifies whether a subsystem supports human segmentation depth image. /// public Func humanSegmentationDepthImageSupportedDelegate { get; set; } /// /// Specifies whether a subsystem supports temporal smoothing of the environment depth image. /// /// A method delegate indicating support for temporal smoothing of the environment depth image. public Func environmentDepthTemporalSmoothingSupportedDelegate { get; set; } /// /// Query for whether the current subsystem supports environment depth image. This property is deprecated. Use /// instead. /// /// /// true if the current subsystem supports environment depth image. Otherwise, false. /// [Obsolete("Use " + nameof(environmentDepthImageSupportedDelegate) + " instead.")] public Func queryForSupportsEnvironmentDepthImage { get; set; } /// /// Query for whether the current subsystem supports environment depth image. /// public Func environmentDepthImageSupportedDelegate { get; set; } /// /// Specifies if the current subsystem supports environment depth confidence image. This property is deprecated. /// Use instead. /// /// /// true if the current subsystem supports environment depth confidence image. Otherwise, false. /// [Obsolete("Use " + nameof(environmentDepthConfidenceImageSupportedDelegate) + " instead.")] public Func queryForSupportsEnvironmentDepthConfidenceImage { get; set; } /// /// Specifies if the current subsystem supports environment depth confidence image. /// public Func environmentDepthConfidenceImageSupportedDelegate { get; set; } /// /// Tests for equality. /// /// The other to compare against. /// `True` if every field in is equal to this , otherwise false. public bool Equals(XROcclusionSubsystemCinfo other) { return ReferenceEquals(id, other.id) && ReferenceEquals(providerType, other.providerType) && ReferenceEquals(subsystemTypeOverride, other.subsystemTypeOverride) #pragma warning disable CS0618 // obsolete && supportsHumanSegmentationStencilImage.Equals(other.supportsHumanSegmentationStencilImage) && supportsHumanSegmentationDepthImage.Equals(other.supportsHumanSegmentationDepthImage) && ReferenceEquals(queryForSupportsEnvironmentDepthImage, other.queryForSupportsEnvironmentDepthImage) && ReferenceEquals(queryForSupportsEnvironmentDepthConfidenceImage, other.queryForSupportsEnvironmentDepthConfidenceImage) #pragma warning restore CS0618 && humanSegmentationDepthImageSupportedDelegate == other.humanSegmentationDepthImageSupportedDelegate && humanSegmentationStencilImageSupportedDelegate == other.humanSegmentationStencilImageSupportedDelegate && environmentDepthImageSupportedDelegate == other.environmentDepthImageSupportedDelegate && environmentDepthTemporalSmoothingSupportedDelegate == other.environmentDepthTemporalSmoothingSupportedDelegate && environmentDepthConfidenceImageSupportedDelegate == other.environmentDepthConfidenceImageSupportedDelegate; } /// /// Tests for equality. /// /// The `object` to compare against. /// `True` if is of type and /// also returns `true`; otherwise `false`. public override bool Equals(System.Object obj) => ((obj is XROcclusionSubsystemCinfo) && Equals((XROcclusionSubsystemCinfo)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 ==(XROcclusionSubsystemCinfo lhs, XROcclusionSubsystemCinfo 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 !=(XROcclusionSubsystemCinfo lhs, XROcclusionSubsystemCinfo rhs) => !lhs.Equals(rhs); /// /// 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() { int hashCode = 486187739; unchecked { hashCode = (hashCode * 486187739) + HashCodeUtil.ReferenceHash(id); hashCode = (hashCode * 486187739) + HashCodeUtil.ReferenceHash(providerType); hashCode = (hashCode * 486187739) + HashCodeUtil.ReferenceHash(subsystemTypeOverride); hashCode = HashCodeUtil.Combine(hashCode, #pragma warning disable CS0618 // obsolete supportsHumanSegmentationStencilImage.GetHashCode(), supportsHumanSegmentationDepthImage.GetHashCode(), HashCodeUtil.ReferenceHash(queryForSupportsEnvironmentDepthImage), HashCodeUtil.ReferenceHash(queryForSupportsEnvironmentDepthConfidenceImage), #pragma warning restore CS0618 HashCodeUtil.ReferenceHash(humanSegmentationStencilImageSupportedDelegate), HashCodeUtil.ReferenceHash(humanSegmentationDepthImageSupportedDelegate), HashCodeUtil.ReferenceHash(environmentDepthImageSupportedDelegate), HashCodeUtil.ReferenceHash(environmentDepthTemporalSmoothingSupportedDelegate), HashCodeUtil.ReferenceHash(environmentDepthConfidenceImageSupportedDelegate)); } return hashCode; } } /// /// Descriptor for the XROcclusionSubsystem. /// public class XROcclusionSubsystemDescriptor : SubsystemDescriptorWithProvider { XROcclusionSubsystemDescriptor(XROcclusionSubsystemCinfo occlusionSubsystemCinfo) { id = occlusionSubsystemCinfo.id; providerType = occlusionSubsystemCinfo.providerType; subsystemTypeOverride = occlusionSubsystemCinfo.subsystemTypeOverride; #pragma warning disable CS0618 // obsolete m_SupportsHumanSegmentationStencilImage = occlusionSubsystemCinfo.supportsHumanSegmentationStencilImage; m_SupportsHumanSegmentationDepthImage = occlusionSubsystemCinfo.supportsHumanSegmentationDepthImage; m_QueryForSupportsEnvironmentDepthImage = occlusionSubsystemCinfo.queryForSupportsEnvironmentDepthImage; m_QueryForSupportsEnvironmentDepthConfidenceImage = occlusionSubsystemCinfo.queryForSupportsEnvironmentDepthConfidenceImage; #pragma warning restore CS0618 m_EnvironmentDepthImageSupportedDelegate = occlusionSubsystemCinfo.environmentDepthImageSupportedDelegate; m_EnvironmentDepthConfidenceImageSupportedDelegate = occlusionSubsystemCinfo.environmentDepthConfidenceImageSupportedDelegate; m_HumanSegmentationStencilImageSupportedDelegate = occlusionSubsystemCinfo.humanSegmentationStencilImageSupportedDelegate; m_HumanSegmentationDepthImageSupportedDelegate = occlusionSubsystemCinfo.humanSegmentationDepthImageSupportedDelegate; m_EnvironmentDepthTemporalSmoothingSupportedDelegate = occlusionSubsystemCinfo.environmentDepthTemporalSmoothingSupportedDelegate; } /// /// Query for whether environment depth is supported. /// /// /// true if the current subsystem supports environment depth image. Otherwise, false. /// /// /// On some platforms, this is a runtime check that requires an active session. /// [Obsolete("Use " + nameof(m_EnvironmentDepthImageSupportedDelegate) + " instead.")] Func m_QueryForSupportsEnvironmentDepthImage; /// /// Query for whether environment depth is supported. /// Func m_EnvironmentDepthImageSupportedDelegate; /// /// Query for whether environment depth confidence is supported. /// /// /// true if the current subsystem supports environment depth confidence image. Otherwise, false. /// /// /// On some platforms, this is a runtime check that requires an active session. /// [Obsolete("Use " + nameof(m_EnvironmentDepthConfidenceImageSupportedDelegate) + " instead.")] Func m_QueryForSupportsEnvironmentDepthConfidenceImage; /// /// Query for whether environment depth confidence is supported. /// Func m_EnvironmentDepthConfidenceImageSupportedDelegate; /// /// Specifies if the current subsystem supports human segmentation stencil image. This property is deprecated. /// Use instead. /// /// /// > [!NOTE] /// > This is a runtime check which might require some initialization to determine support. During this period, /// > this property may return `false` for a time before becoming `true`. /// /// /// true if the current subsystem supports human segmentation stencil image. Otherwise, false. /// [Obsolete("Use " + nameof(humanSegmentationStencilImageSupported) + " instead.")] public bool supportsHumanSegmentationStencilImage => humanSegmentationStencilImageSupported == Supported.Supported; bool m_SupportsHumanSegmentationStencilImage; /// /// (Read Only) Whether a subsystem supports human segmentation stencil image. /// public Supported humanSegmentationStencilImageSupported { get { if (m_HumanSegmentationStencilImageSupportedDelegate != null) { return m_HumanSegmentationStencilImageSupportedDelegate(); } return m_SupportsHumanSegmentationStencilImage ? Supported.Supported : Supported.Unsupported; } } Func m_HumanSegmentationStencilImageSupportedDelegate; /// /// Specifies if the current subsystem supports human segmentation depth image. This property is deprecated. /// Use instead. /// /// /// > [!NOTE] /// > This is a runtime check which might require some initialization to determine support. During this period, /// > this property might return `false` for a time before becoming `true`. /// /// /// true if the current subsystem supports human segmentation depth image. Otherwise, false. /// [Obsolete("Use " + nameof(humanSegmentationDepthImageSupported) + " instead.")] public bool supportsHumanSegmentationDepthImage => humanSegmentationDepthImageSupported == Supported.Supported; bool m_SupportsHumanSegmentationDepthImage; /// /// (Read Only) Whether a subsystem supports human segmentation depth image. /// public Supported humanSegmentationDepthImageSupported { get { if (m_HumanSegmentationDepthImageSupportedDelegate != null) { return m_HumanSegmentationDepthImageSupportedDelegate(); } return m_SupportsHumanSegmentationDepthImage ? Supported.Supported : Supported.Unsupported; } } Func m_HumanSegmentationDepthImageSupportedDelegate; /// /// Specifies if the current subsystem supports environment depth image. This property is deprecated. /// Use instead. /// /// /// > [!NOTE] /// > This is a runtime check which might require some initialization to determine support. During this period, /// > this property might return `false` for a time before becoming `true`. /// /// /// true if the current subsystem supports environment depth image. Otherwise, false. /// [Obsolete("Use " + nameof(environmentDepthImageSupported) + " instead.")] public bool supportsEnvironmentDepthImage => environmentDepthImageSupported == Supported.Supported; /// /// (Read Only) Whether the subsystem supports environment depth image. /// /// /// The supported status might take time to determine. If support is still being determined, the value will be . /// public Supported environmentDepthImageSupported { get { if (m_EnvironmentDepthImageSupportedDelegate != null) { return m_EnvironmentDepthImageSupportedDelegate(); } #pragma warning disable CS0618 // obsolete // Check deprecated fallback return m_QueryForSupportsEnvironmentDepthImage?.Invoke() == true ? Supported.Supported : Supported.Unsupported; #pragma warning restore CS0618 } } Func m_EnvironmentDepthTemporalSmoothingSupportedDelegate; /// /// Whether temporal smoothing of the environment image is supported. /// /// Read Only. public Supported environmentDepthTemporalSmoothingSupported => m_EnvironmentDepthTemporalSmoothingSupportedDelegate?.Invoke() ?? Supported.Unsupported; /// /// Specifies if the current subsystem supports environment depth confidence image. This property is deprecated. /// Use instead. /// /// /// > [!NOTE] /// > This is a runtime check which might require some initialization to determine support. During this period, /// > this property might return `false` for a time before becoming `true`. /// /// /// true if the current subsystem supports environment depth confidence image. Otherwise, false. /// [Obsolete("Use " + nameof(environmentDepthConfidenceImageSupported) + " instead.")] public bool supportsEnvironmentDepthConfidenceImage => environmentDepthConfidenceImageSupported == Supported.Supported; /// /// (Read Only) Whether the subsystem supports environment depth confidence image. /// /// /// The supported status might take time to determine. If support is still being determined, the value will be . /// public Supported environmentDepthConfidenceImageSupported { get { if (m_EnvironmentDepthConfidenceImageSupportedDelegate != null) { return m_EnvironmentDepthConfidenceImageSupportedDelegate(); } #pragma warning disable CS0618 // obsolete // Check deprecated fallback return m_QueryForSupportsEnvironmentDepthConfidenceImage?.Invoke() == true ? Supported.Supported : Supported.Unsupported; #pragma warning restore CS0618 } } /// /// Creates the occlusion subsystem descriptor from the construction info. /// /// The occlusion subsystem descriptor constructor information. internal static XROcclusionSubsystemDescriptor Create(XROcclusionSubsystemCinfo occlusionSubsystemCinfo) { if (string.IsNullOrEmpty(occlusionSubsystemCinfo.id)) { throw new ArgumentException("Cannot create occlusion subsystem descriptor because id is invalid", nameof(occlusionSubsystemCinfo)); } if (occlusionSubsystemCinfo.providerType == null || !occlusionSubsystemCinfo.providerType.IsSubclassOf(typeof(XROcclusionSubsystem.Provider))) { throw new ArgumentException("Cannot create occlusion subsystem descriptor because providerType is invalid", nameof(occlusionSubsystemCinfo)); } if (occlusionSubsystemCinfo.subsystemTypeOverride == null || !occlusionSubsystemCinfo.subsystemTypeOverride.IsSubclassOf(typeof(XROcclusionSubsystem))) { throw new ArgumentException("Cannot create occlusion subsystem descriptor because subsystemTypeOverride is invalid", nameof(occlusionSubsystemCinfo)); } return new XROcclusionSubsystemDescriptor(occlusionSubsystemCinfo); } } }