using System;
namespace UnityEngine.XR.ARSubsystems
{
///
/// Represents a session configuration. It consists of a configuration , which
/// contains information about the capabilities of the configuration, and the specific
/// which should be enabled by this configuration. Use
/// to get a given a set of features.
///
///
///
///
public struct Configuration : IEquatable
{
///
/// The descriptor contains information about the capabilities of a configuration.
///
public ConfigurationDescriptor descriptor { get; private set; }
///
/// The specific (s) that should be enabled by this configuration.
///
///
/// You can ony enable exactly zero or one camera modes (see and ).
/// If zero camera modes are enabled, no camera texture will be available. Some platforms might support a configuration that does
/// not provide camera textures, which can be more performant if they are not necessary.
/// All enabled features must be supported by the .
///
public Feature features { get; private set; }
///
/// Constructs a .
///
/// A for this configuration.
/// A set of (s) that should be enabled for this configuration.
/// You can only enable exactly zero or one camera modes (see and ).
/// If zero camera modes are enabled, no camera texture will be available. Some platforms might support a configuration that does
/// not provide camera textures, which can be more performant if they are not necessary.
/// All must be supported by the .
/// Thrown if multiple camera modes are enabled.
/// Thrown if multiple tracking modes are enabled.
/// Thrown if the does not support one or more .
public Configuration(ConfigurationDescriptor descriptor, Feature features)
{
if (!descriptor.capabilities.All(features))
throw new NotSupportedException($"The configuration does not support the following requested features: {features.SetDifference(descriptor.capabilities).ToStringList()}.");
var cameraMode = features.Cameras();
if (cameraMode.Any(Feature.AnyCamera))
{
if (cameraMode.Count() > 1)
throw new InvalidOperationException($"Either zero or one camera mode must be enabled. The following modes are enabled: {cameraMode.ToStringList()}");
}
var trackingMode = features.TrackingModes();
if (trackingMode.Count() > 1)
throw new InvalidOperationException($"Either zero or one tracking modes must be enabled. The following modes are enabled: {trackingMode.ToStringList()}");
this.descriptor = descriptor;
this.features = features;
}
///
/// Generates a hash code suitable for use in a Dictionary or HashSet.
///
/// A hash code of this .
public override int GetHashCode() => HashCodeUtil.Combine(descriptor.GetHashCode(), features.GetHashCode());
///
/// Compares for equality.
///
/// The other to compare against.
/// true if the other is equal to this one.
public bool Equals(Configuration other) => descriptor.Equals(other.descriptor) && (features == other.features);
///
/// Compares for equality.
///
/// The object to compare against.
/// true if is of type and is true.
public override bool Equals(object obj) => (obj is Configuration) && Equals((Configuration)obj);
///
/// Compares for equality.
///
/// The left-hand side of the comparison.
/// The right-hand side of the comparison.
/// The same as .
public static bool operator==(Configuration lhs, Configuration rhs) => lhs.Equals(rhs);
///
/// Compares for inequality.
///
/// The left-hand side of the comparison.
/// The right-hand side of the comparison.
/// The negation of .
public static bool operator!=(Configuration lhs, Configuration rhs) => !lhs.Equals(rhs);
}
}