XRCameraSubsystemDescriptor.cs
21.3 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
using System;
#if UNITY_2020_2_OR_NEWER
using UnityEngine.SubsystemsImplementation;
#endif
namespace UnityEngine.XR.ARSubsystems
{
/// <summary>
/// Encapsulates the parameters for creating a new <see cref="XRCameraSubsystemDescriptor"/>.
/// </summary>
public struct XRCameraSubsystemCinfo : IEquatable<XRCameraSubsystemCinfo>
{
/// <summary>
/// Specifies an identifier for the provider implementation of the subsystem.
/// </summary>
/// <value>
/// The identifier for the provider implementation of the subsystem.
/// </value>
public string id { get; set; }
#if UNITY_2020_2_OR_NEWER
/// <summary>
/// Specifies the provider implementation type to use for instantiation.
/// </summary>
/// <value>
/// The provider implementation type to use for instantiation.
/// </value>
public Type providerType { get; set; }
/// <summary>
/// Specifies the <c>XRCameraSubsystem</c>-derived type that forwards casted calls to its provider.
/// </summary>
/// <value>
/// The type of the subsystem to use for instantiation. If null, <c>XRCameraSubsystem</c> will be instantiated.
/// </value>
public Type subsystemTypeOverride { get; set; }
#endif
/// <summary>
/// Specifies the provider implementation type to use for instantiation.
/// </summary>
/// <value>
/// The provider implementation type to use for instantiation.
/// </value>
#if UNITY_2020_2_OR_NEWER
[Obsolete("XRCameraSubsystem no longer supports the deprecated set of base classes for subsystems as of Unity 2020.2. Use providerType and, optionally, subsystemTypeOverride instead.", true)]
#endif
public Type implementationType { get; set; }
/// <summary>
/// Specifies if current subsystem is allowed to provide average brightness.
/// </summary>
/// <value>
/// <c>true</c> if current subsystem is allowed to provide average brightness. Otherwise, <c>false</c>.
/// </value>
public bool supportsAverageBrightness { get; set; }
/// <summary>
/// Specifies if current subsystem is allowed to provide average camera temperature.
/// </summary>
/// <value>
/// <c>true</c> if current subsystem is allowed to provide average camera temperature. Otherwise, <c>false</c>.
/// </value>
public bool supportsAverageColorTemperature { get; set; }
/// <summary>
/// True if color correction is supported.
/// </summary>
public bool supportsColorCorrection { get; set; }
/// <summary>
/// Specifies if current subsystem is allowed to provide display matrix.
/// </summary>
/// <value>
/// <c>true</c> if current subsystem is allowed to provide display matrix. Otherwise, <c>false</c>.
/// </value>
public bool supportsDisplayMatrix { get; set; }
/// <summary>
/// Specifies if current subsystem is allowed to provide projection matrix.
/// </summary>
/// <value>
/// <c>true</c> if current subsystem is allowed to provide projection matrix. Otherwise, <c>false</c>.
/// </value>
public bool supportsProjectionMatrix { get; set; }
/// <summary>
/// Specifies if current subsystem is allowed to provide timestamp.
/// </summary>
/// <value>
/// <c>true</c> if current subsystem is allowed to provide timestamp. Otherwise, <c>false</c>.
/// </value>
public bool supportsTimestamp { get; set; }
/// <summary>
/// Specifies if the current subsystem supports camera configurations.
/// </summary>
/// <value>
/// <c>true</c> if the current subsystem supports camera configurations. Otherwise, <c>false</c>.
/// </value>
public bool supportsCameraConfigurations { get; set; }
/// <summary>
/// Specifies if the current subsystem is allowed to provide camera images.
/// </summary>
/// <value>
/// <c>true</c> if the current subsystem is allowed to provide camera images. Otherwise, <c>false</c>.
/// </value>
public bool supportsCameraImage { get; set; }
/// <summary>
/// Specifies if current subsystem is allowed to provide average intensity in lumens.
/// </summary>
/// <value>
/// <c>true</c> if current subsystem is allowed to provide average intensity in lumens. Otherwise, <c>false</c>.
/// </value>
public bool supportsAverageIntensityInLumens { get; set; }
/// <summary>
/// Specifies whether the subsystem supports ambient intensity light estimation while face tracking.
/// </summary>
public bool supportsFaceTrackingAmbientIntensityLightEstimation { get; set; }
/// <summary>
/// Specifies whether the subsystem supports HDR light estimation while face tracking.
/// </summary>
public bool supportsFaceTrackingHDRLightEstimation { get; set; }
/// <summary>
/// Specifies whether the subsystem supports ambient intensity light estimation while world tracking.
/// </summary>
public bool supportsWorldTrackingAmbientIntensityLightEstimation { get; set; }
/// <summary>
/// Specifies whether the subsystem supports HDR light estimation while world tracking.
/// </summary>
public bool supportsWorldTrackingHDRLightEstimation { get; set; }
/// <summary>
/// Specifies whether the subsystem supports setting the camera's focus mode.
/// </summary>
public bool supportsFocusModes { get; set; }
/// <summary>
/// Specifies whether the subsystem supports camera grain effect.
/// </summary>
public bool supportsCameraGrain { get; set; }
/// <summary>
/// Tests for equality.
/// </summary>
/// <param name="other">The other <see cref="XRCameraSubsystemCinfo"/> to compare against.</param>
/// <returns>`True` if every field in <paramref name="other"/> is equal to this <see cref="XRCameraSubsystemCinfo"/>, otherwise false.</returns>
public bool Equals(XRCameraSubsystemCinfo other)
{
return
ReferenceEquals(id, other.id)
#if UNITY_2020_2_OR_NEWER
&& ReferenceEquals(providerType, other.providerType)
&& ReferenceEquals(subsystemTypeOverride, other.subsystemTypeOverride)
#else
&& ReferenceEquals(implementationType, other.implementationType)
#endif
&& supportsAverageBrightness.Equals(other.supportsAverageBrightness)
&& supportsAverageColorTemperature.Equals(other.supportsAverageColorTemperature)
&& supportsColorCorrection.Equals(other.supportsColorCorrection)
&& supportsDisplayMatrix.Equals(other.supportsDisplayMatrix)
&& supportsProjectionMatrix.Equals(other.supportsProjectionMatrix)
&& supportsTimestamp.Equals(other.supportsTimestamp)
&& supportsCameraConfigurations.Equals(other.supportsCameraConfigurations)
&& supportsCameraImage.Equals(other.supportsCameraImage)
&& supportsAverageIntensityInLumens.Equals(other.supportsAverageIntensityInLumens)
&& supportsFaceTrackingAmbientIntensityLightEstimation.Equals(other.supportsFaceTrackingAmbientIntensityLightEstimation)
&& supportsFaceTrackingHDRLightEstimation.Equals(other.supportsFaceTrackingHDRLightEstimation)
&& supportsWorldTrackingAmbientIntensityLightEstimation.Equals(other.supportsWorldTrackingAmbientIntensityLightEstimation)
&& supportsWorldTrackingHDRLightEstimation.Equals(other.supportsWorldTrackingHDRLightEstimation)
&& supportsFocusModes.Equals(other.supportsFocusModes)
&& supportsCameraGrain.Equals(other.supportsCameraGrain);
}
/// <summary>
/// Tests for equality.
/// </summary>
/// <param name="obj">The `object` to compare against.</param>
/// <returns>`True` if <paramref name="obj"/> is of type <see cref="XRCameraSubsystemCinfo"/> and
/// <see cref="Equals(XRCameraSubsystemCinfo)"/> also returns `true`; otherwise `false`.</returns>
public override bool Equals(System.Object obj)
{
return ((obj is XRCameraSubsystemCinfo) && Equals((XRCameraSubsystemCinfo)obj));
}
/// <summary>
/// Tests for equality. Same as <see cref="Equals(XRCameraSubsystemCinfo)"/>.
/// </summary>
/// <param name="lhs">The left-hand side of the comparison.</param>
/// <param name="rhs">The right-hand side of the comparison.</param>
/// <returns>`True` if <paramref name="lhs"/> is equal to <paramref name="rhs"/>, otherwise `false`.</returns>
public static bool operator ==(XRCameraSubsystemCinfo lhs, XRCameraSubsystemCinfo rhs) => lhs.Equals(rhs);
/// <summary>
/// Tests for inequality. Same as `!`<see cref="Equals(XRCameraSubsystemCinfo)"/>.
/// </summary>
/// <param name="lhs">The left-hand side of the comparison.</param>
/// <param name="rhs">The right-hand side of the comparison.</param>
/// <returns>`True` if <paramref name="lhs"/> is not equal to <paramref name="rhs"/>, otherwise `false`.</returns>
public static bool operator !=(XRCameraSubsystemCinfo lhs, XRCameraSubsystemCinfo rhs) => !lhs.Equals(rhs);
/// <summary>
/// Generates a hash suitable for use with containers like `HashSet` and `Dictionary`.
/// </summary>
/// <returns>A hash code generated from this object's fields.</returns>
public override int GetHashCode()
{
int hashCode = 486187739;
unchecked
{
hashCode = (hashCode * 486187739) + HashCode.ReferenceHash(id);
#if UNITY_2020_2_OR_NEWER
hashCode = (hashCode * 486187739) + HashCode.ReferenceHash(providerType);
hashCode = (hashCode * 486187739) + HashCode.ReferenceHash(subsystemTypeOverride);
#else
hashCode = (hashCode * 486187739) + HashCode.ReferenceHash(implementationType);
#endif
hashCode = (hashCode * 486187739) + supportsAverageBrightness.GetHashCode();
hashCode = (hashCode * 486187739) + supportsAverageColorTemperature.GetHashCode();
hashCode = (hashCode * 486187739) + supportsColorCorrection.GetHashCode();
hashCode = (hashCode * 486187739) + supportsDisplayMatrix.GetHashCode();
hashCode = (hashCode * 486187739) + supportsProjectionMatrix.GetHashCode();
hashCode = (hashCode * 486187739) + supportsTimestamp.GetHashCode();
hashCode = (hashCode * 486187739) + supportsCameraConfigurations.GetHashCode();
hashCode = (hashCode * 486187739) + supportsCameraImage.GetHashCode();
hashCode = (hashCode * 486187739) + supportsAverageIntensityInLumens.GetHashCode();
hashCode = (hashCode * 486187739) + supportsFaceTrackingAmbientIntensityLightEstimation.GetHashCode();
hashCode = (hashCode * 486187739) + supportsFaceTrackingHDRLightEstimation.GetHashCode();
hashCode = (hashCode * 486187739) + supportsWorldTrackingAmbientIntensityLightEstimation.GetHashCode();
hashCode = (hashCode * 486187739) + supportsWorldTrackingHDRLightEstimation.GetHashCode();
hashCode = (hashCode * 486187739) + supportsFocusModes.GetHashCode();
hashCode = (hashCode * 486187739) + supportsCameraGrain.GetHashCode();
}
return hashCode;
}
}
/// <summary>
/// Specifies a functionality description that may be registered for each implementation that provides the
/// <see cref="XRCameraSubsystem"/> interface.
/// </summary>
public sealed class XRCameraSubsystemDescriptor :
#if UNITY_2020_2_OR_NEWER
SubsystemDescriptorWithProvider<XRCameraSubsystem, XRCameraSubsystem.Provider>
#else
SubsystemDescriptor<XRCameraSubsystem>
#endif
{
/// <summary>
/// Constructs a <c>XRCameraSubsystemDescriptor</c> based on the given parameters.
/// </summary>
/// <param name="cameraSubsystemParams">The parameters required to initialize the descriptor.</param>
XRCameraSubsystemDescriptor(XRCameraSubsystemCinfo cameraSubsystemParams)
{
id = cameraSubsystemParams.id;
#if UNITY_2020_2_OR_NEWER
providerType = cameraSubsystemParams.providerType;
subsystemTypeOverride = cameraSubsystemParams.subsystemTypeOverride;
#else
subsystemImplementationType = cameraSubsystemParams.implementationType;
#endif
supportsAverageBrightness = cameraSubsystemParams.supportsAverageBrightness;
supportsAverageColorTemperature = cameraSubsystemParams.supportsAverageColorTemperature;
supportsColorCorrection = cameraSubsystemParams.supportsColorCorrection;
supportsDisplayMatrix = cameraSubsystemParams.supportsDisplayMatrix;
supportsProjectionMatrix = cameraSubsystemParams.supportsProjectionMatrix;
supportsTimestamp = cameraSubsystemParams.supportsTimestamp;
supportsCameraConfigurations = cameraSubsystemParams.supportsCameraConfigurations;
supportsCameraImage = cameraSubsystemParams.supportsCameraImage;
supportsAverageIntensityInLumens = cameraSubsystemParams.supportsAverageIntensityInLumens;
supportsFocusModes = cameraSubsystemParams.supportsFocusModes;
supportsFaceTrackingAmbientIntensityLightEstimation = cameraSubsystemParams.supportsFaceTrackingAmbientIntensityLightEstimation;
supportsFaceTrackingHDRLightEstimation = cameraSubsystemParams.supportsFaceTrackingHDRLightEstimation;
supportsWorldTrackingAmbientIntensityLightEstimation = cameraSubsystemParams.supportsWorldTrackingAmbientIntensityLightEstimation;
supportsWorldTrackingHDRLightEstimation = cameraSubsystemParams.supportsWorldTrackingHDRLightEstimation;
supportsCameraGrain = cameraSubsystemParams.supportsCameraGrain;
}
/// <summary>
/// Specifies if current subsystem is allowed to provide average brightness.
/// </summary>
/// <value>
/// <c>true</c> if current subsystem is allowed to provide average brightness. Otherwise, <c>false</c>.
/// </value>
public bool supportsAverageBrightness { get; private set; }
/// <summary>
/// Specifies if current subsystem is allowed to provide average camera temperature.
/// </summary>
/// <value>
/// <c>true</c> if current subsystem is allowed to provide average camera temperature. Otherwise, <c>false</c>.
/// </value>
public bool supportsAverageColorTemperature { get; private set; }
/// <summary>
/// Specifies if current subsystem is allowed to provide color correction.
/// </summary>
public bool supportsColorCorrection { get; private set; }
/// <summary>
/// Specifies if current subsystem is allowed to provide display matrix.
/// </summary>
/// <value>
/// <c>true</c> if current subsystem is allowed to provide display matrix. Otherwise, <c>false</c>.
/// </value>
public bool supportsDisplayMatrix { get; private set; }
/// <summary>
/// Specifies if current subsystem is allowed to provide projection matrix.
/// </summary>
/// <value>
/// <c>true</c> if current subsystem is allowed to provide projection matrix. Otherwise, <c>false</c>.
/// </value>
public bool supportsProjectionMatrix { get; private set; }
/// <summary>
/// Specifies if current subsystem is allowed to provide timestamp.
/// </summary>
/// <value>
/// <c>true</c> if current subsystem is allowed to provide timestamp. Otherwise, <c>false</c>.
/// </value>
public bool supportsTimestamp { get; private set; }
/// <summary>
/// Specifies if the current subsystem supports camera configurations.
/// </summary>
/// <value>
/// <c>true</c> if the current subsystem supports camera configurations. Otherwise, <c>false</c>.
/// </value>
public bool supportsCameraConfigurations { get; private set; }
/// <summary>
/// Specifies if the current subsystem is allowed to provide camera images.
/// </summary>
/// <value>
/// <c>true</c> if the current subsystem is allowed to provide camera images. Otherwise, <c>false</c>.
/// </value>
public bool supportsCameraImage { get; private set; }
/// <summary>
/// Specifies if current subsystem is allowed to provide average intensity in lumens.
/// </summary>
/// <value>
/// <c>true</c> if current subsystem is allowed to provide average intensity in lumens. Otherwise, <c>false</c>.
/// </value>
public bool supportsAverageIntensityInLumens { get; private set; }
/// <summary>
/// Specifies whether the subsystem supports setting the camera's focus mode.
/// </summary>
public bool supportsFocusModes { get; private set; }
/// <summary>
/// Specifies whether the subsystem supports ambient intensity light estimation while face tracking.
/// </summary>
public bool supportsFaceTrackingAmbientIntensityLightEstimation { get; private set; }
/// <summary>
/// Specifies whether the subsystem supports HDR light estimation while face tracking.
/// </summary>
public bool supportsFaceTrackingHDRLightEstimation { get; private set; }
/// <summary>
/// Specifies whether the subsystem supports ambient intensity light estimation while world tracking.
/// </summary>
public bool supportsWorldTrackingAmbientIntensityLightEstimation { get; private set; }
/// <summary>
/// Specifies whether the subsystem supports HDR light estimation while world tracking.
/// </summary>
public bool supportsWorldTrackingHDRLightEstimation { get; private set; }
/// <summary>
/// Specifies whether the subsystem supports camera grain effect.
/// </summary>
public bool supportsCameraGrain { get; private set; }
/// <summary>
/// Creates a <c>XRCameraSubsystemDescriptor</c> based on the given parameters validating that the
/// <see cref="XRCameraSubsystemCinfo.id"/> and <see cref="XRCameraSubsystemCinfo.implementationType"/>
/// properties are properly specified.
/// </summary>
/// <param name="cameraSubsystemParams">The parameters defining how to initialize the descriptor.</param>
/// <returns>
/// The created <c>XRCameraSubsystemDescriptor</c>.
/// </returns>
/// <exception cref="System.ArgumentException">Thrown when the values specified in the
/// <see cref="XRCameraSubsystemCinfo"/> parameter are invalid. Typically, this will occur
/// <list type="bullet">
/// <item>
/// <description>if <see cref="XRCameraSubsystemCinfo.id"/> is <c>null</c> or empty</description>
/// </item>
/// <item>
/// <description>if <see cref="XRCameraSubsystemCinfo.implementationType"/> is <c>null</c></description>
/// </item>
/// <item>
/// <description>if <see cref="XRCameraSubsystemCinfo.implementationType"/> does not derive from the
/// <see cref="XRCameraSubsystem"/> class
/// </description>
/// </item>
/// </list>
/// </exception>
internal static XRCameraSubsystemDescriptor Create(XRCameraSubsystemCinfo cameraSubsystemParams)
{
if (String.IsNullOrEmpty(cameraSubsystemParams.id))
{
throw new ArgumentException("Cannot create camera subsystem descriptor because id is invalid",
"cameraSubsystemParams");
}
#if UNITY_2020_2_OR_NEWER
if (cameraSubsystemParams.providerType == null
|| !cameraSubsystemParams.providerType.IsSubclassOf(typeof(XRCameraSubsystem.Provider)))
{
throw new ArgumentException("Cannot create camera subsystem descriptor because providerType is invalid", "cameraSubsystemParams");
}
if (cameraSubsystemParams.subsystemTypeOverride != null
&& !cameraSubsystemParams.subsystemTypeOverride.IsSubclassOf(typeof(XRCameraSubsystem)))
{
throw new ArgumentException("Cannot create camera subsystem descriptor because subsystemTypeOverride is invalid", "cameraSubsystemParams");
}
#else
if ((cameraSubsystemParams.implementationType == null)
|| !cameraSubsystemParams.implementationType.IsSubclassOf(typeof(XRCameraSubsystem)))
{
throw new ArgumentException("Cannot create camera subsystem descriptor because implementationType is invalid",
"cameraSubsystemParams");
}
#endif
return new XRCameraSubsystemDescriptor(cameraSubsystemParams);
}
}
}