Configuration.cs
5.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
namespace UnityEngine.XR.ARSubsystems
{
/// <summary>
/// Represents a session configuration. It consists of a configuration <see cref="descriptor"/>, which
/// contains information about the capabilities of the configuration, and the specific <see cref="features"/>
/// which should be enabled by this configuration. Use <see cref="XRSessionSubsystem.DetermineConfiguration(Feature)"/>
/// to get a <see cref="Configuration"/> given a set of features.
/// </summary>
/// <seealso cref="ConfigurationChooser"/>
/// <seealso cref="XRSessionSubsystem.configurationChooser"/>
/// <seealso cref="XRSessionSubsystem.DetermineConfiguration(Feature)"/>
public struct Configuration : IEquatable<Configuration>
{
/// <summary>
/// The descriptor contains information about the capabilities of a configuration.
/// </summary>
public ConfigurationDescriptor descriptor { get; private set; }
/// <summary>
/// The specific <see cref="Feature"/>(s) that should be enabled by this configuration.
/// </summary>
/// <remarks>
/// Exactly zero or one camera mode must be enabled (see <see cref="Feature.UserFacingCamera"/> and <see cref="Feature.WorldFacingCamera"/>).
/// If zero camera modes are enabled, no camera texture will be available. Some platforms may 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 <see cref="descriptor"/>.
/// </remarks>
public Feature features { get; private set; }
/// <summary>
/// Constructs a <see cref="Configuration"/>.
/// </summary>
/// <param name="descriptor">A <see cref="ConfigurationDescriptor"/> for this configuration.</param>
/// <param name="features">A set of <see cref="Feature"/>(s) that should be enabled for this configuration.
/// Exactly zero or one camera mode must be enabled (see <see cref="Feature.UserFacingCamera"/> and <see cref="Feature.WorldFacingCamera"/>).
/// If zero camera modes are enabled, no camera texture will be available. Some platforms may support a configuration that does
/// not provide camera textures, which can be more performant if they are not necessary.
/// All <paramref name="features"/> must be supported by the <paramref name="descriptor"/>.</param>
/// <exception cref="System.InvalidOperationException">Thrown if multiple camera modes are enabled.</exception>
/// <exception cref="System.InvalidOperationException">Thrown if multiple tracking modes are enabled.</exception>
/// <exception cref="System.NotSupportedException">Thrown if the <paramref name="descriptor"/> does not support one or more <paramref name="features"/>.</exception>
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;
}
/// <summary>
/// Generates a hash code suitable for use in a Dictionary or HashSet.
/// </summary>
/// <returns>A hash code of this <see cref="Configuration"/>.</returns>
public override int GetHashCode() => HashCode.Combine(descriptor.GetHashCode(), features.GetHashCode());
/// <summary>
/// Compares for equality.
/// </summary>
/// <param name="other">The other <see cref="Configuration"/> to compare against.</param>
/// <returns><c>true</c> if the other <see cref="Configuration"/> is equal to this one.</returns>
public bool Equals(Configuration other) => descriptor.Equals(other.descriptor) && (features == other.features);
/// <summary>
/// Compares for equality.
/// </summary>
/// <param name="obj">The <c>object</c> to compare against.</param>
/// <returns><c>true</c> if <paramref name="obj"/> is of type <see cref="Configuration"/> and <see cref="Equals(Configuration)"/> is <c>true</c>.</returns>
public override bool Equals(object obj) => (obj is Configuration) && Equals((Configuration)obj);
/// <summary>
/// Compares for equality.
/// </summary>
/// <param name="lhs">The left-hand side of the comparison.</param>
/// <param name="rhs">The right-hand side of the comparison.</param>
/// <returns>The same as <see cref="Equals(Configuration)"/>.</returns>
public static bool operator==(Configuration lhs, Configuration rhs) => lhs.Equals(rhs);
/// <summary>
/// Compares for inequality.
/// </summary>
/// <param name="lhs">The left-hand side of the comparison.</param>
/// <param name="rhs">The right-hand side of the comparison.</param>
/// <returns>The negation of <see cref="Equals(Configuration)"/>.</returns>
public static bool operator!=(Configuration lhs, Configuration rhs) => !lhs.Equals(rhs);
}
}