XRImageTrackingSubsystemDescriptor.cs
9.84 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
using System;
#if UNITY_2020_2_OR_NEWER
using UnityEngine.SubsystemsImplementation;
#endif
namespace UnityEngine.XR.ARSubsystems
{
/// <summary>
/// Describes the capabilities of an <see cref="XRImageTrackingSubsystem"/>.
/// </summary>
public class XRImageTrackingSubsystemDescriptor :
#if UNITY_2020_2_OR_NEWER
SubsystemDescriptorWithProvider<XRImageTrackingSubsystem, XRImageTrackingSubsystem.Provider>
#else
SubsystemDescriptor<XRImageTrackingSubsystem>
#endif
{
/// <summary>
/// Construction information for the <see cref="XRImageTrackingSubsystemDescriptor"/>.
/// </summary>
public struct Cinfo : IEquatable<Cinfo>
{
/// <summary>
/// A string identifier used to name the subsystem provider.
/// </summary>
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>XRImageTrackingSubsystem</c>-derived type that forwards casted calls to its provider.
/// </summary>
/// <value>
/// The type of the subsystem to use for instantiation. If null, <c>XRImageTrackingSubsystem</c> will be instantiated.
/// </value>
public Type subsystemTypeOverride { get; set; }
#endif
/// <summary>
/// The <c>System.Type</c> of the provider implementation, used to instantiate the class.
/// </summary>
#if UNITY_2020_2_OR_NEWER
[Obsolete("XRImageTrackingSubsystem 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 subsystemImplementationType { get; set; }
/// <summary>
/// Whether the subsystem supports tracking the poses of moving images in realtime.
/// </summary>
/// <remarks>
/// If <c>true</c>,
/// <see cref="XRImageTrackingSubsystem.Provider.currentMaxNumberOfMovingImages"/> and
/// <see cref="XRImageTrackingSubsystem.Provider.requestedMaxNumberOfMovingImages"/>
/// should be implemented.
/// </remarks>
public bool supportsMovingImages { get; set; }
/// <summary>
/// Whether the subsystem requires physical image dimensions to be provided for all reference images.
/// If <c>false</c>, specifying the physical dimensions is optional.
/// </summary>
public bool requiresPhysicalImageDimensions { get; set; }
/// <summary>
/// Whether the subsystem supports image libraries that may be mutated at runtime.
/// </summary>
/// <remarks>
/// If <c>true</c>,
/// <see cref="XRImageTrackingSubsystem.Provider.CreateRuntimeLibrary(XRReferenceImageLibrary)"/>
/// must be implemented and
/// <see cref="XRImageTrackingSubsystem.Provider.imageLibrary"/>
/// will never be called.
/// </remarks>
/// <seealso cref="MutableRuntimeReferenceImageLibrary"/>
public bool supportsMutableLibrary { get; set; }
/// <summary>
/// Whether the subsystem supports image validation (validating images before they are added to a
/// <see cref="MutableRuntimeReferenceImageLibrary"/>).
/// </summary>
public bool supportsImageValidation { get; set; }
/// <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()
{
unchecked
{
int hashCode = 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(subsystemImplementationType);
#endif
hashCode = hashCode * 486187739 + supportsMovingImages.GetHashCode();
hashCode = hashCode * 486187739 + requiresPhysicalImageDimensions.GetHashCode();
hashCode = hashCode * 486187739 + supportsMutableLibrary.GetHashCode();
hashCode = hashCode * 486187739 + supportsImageValidation.GetHashCode();
return hashCode;
}
}
/// <summary>
/// Tests for equality.
/// </summary>
/// <param name="other">The other <see cref="Cinfo"/> to compare against.</param>
/// <returns>`True` if every field in <paramref name="other"/> is equal to this <see cref="Cinfo"/>, otherwise false.</returns>
public bool Equals(Cinfo other)
{
return
ReferenceEquals(id, other.id) &&
#if UNITY_2020_2_OR_NEWER
ReferenceEquals(providerType, other.providerType) &&
ReferenceEquals(subsystemTypeOverride, other.subsystemTypeOverride) &&
#else
ReferenceEquals(subsystemImplementationType, other.subsystemImplementationType) &&
#endif
supportsMovingImages == other.supportsMovingImages &&
requiresPhysicalImageDimensions == other.requiresPhysicalImageDimensions &&
supportsMutableLibrary == other.supportsMutableLibrary &&
supportsImageValidation == other.supportsImageValidation;
}
/// <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="Cinfo"/> and
/// <see cref="Equals(Cinfo)"/> also returns `true`; otherwise `false`.</returns>
public override bool Equals(object obj) => (obj is Cinfo) && Equals((Cinfo)obj);
/// <summary>
/// Tests for equality. Same as <see cref="Equals(Cinfo)"/>.
/// </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==(Cinfo lhs, Cinfo rhs) => lhs.Equals(rhs);
/// <summary>
/// Tests for inequality. Same as `!`<see cref="Equals(Cinfo)"/>.
/// </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!=(Cinfo lhs, Cinfo rhs) => !lhs.Equals(rhs);
}
/// <summary>
/// Whether the subsystem supports tracking the poses of moving images in realtime.
/// </summary>
public bool supportsMovingImages { get; }
/// <summary>
/// Whether the subsystem requires physical image dimensions to be provided for all reference images.
/// If <c>false</c>, specifying the physical dimensions is optional.
/// </summary>
public bool requiresPhysicalImageDimensions { get; }
/// <summary>
/// Whether the subsystem supports <see cref="MutableRuntimeReferenceImageLibrary"/>, a reference
/// image library which can modified at runtime, as opposed to the <see cref="XRReferenceImageLibrary"/>,
/// which is generated at edit time and cannot be modified at runtime.
/// </summary>
/// <seealso cref="MutableRuntimeReferenceImageLibrary"/>
/// <seealso cref="XRImageTrackingSubsystem.CreateRuntimeLibrary(XRReferenceImageLibrary)"/>
public bool supportsMutableLibrary { get; }
/// <summary>
/// Whether the subsystem supports image validation (validating images before they are added to a
/// <see cref="MutableRuntimeReferenceImageLibrary"/>).
/// </summary>
public bool supportsImageValidation { get; }
/// <summary>
/// Registers a new descriptor with the <c>SubsystemManager</c>.
/// </summary>
/// <param name="cinfo">The construction information for the new descriptor.</param>
public static void Create(Cinfo cinfo)
{
#if UNITY_2020_2_OR_NEWER
SubsystemDescriptorStore.RegisterDescriptor(new XRImageTrackingSubsystemDescriptor(cinfo));
#else
SubsystemRegistration.CreateDescriptor(new XRImageTrackingSubsystemDescriptor(cinfo));
#endif
}
XRImageTrackingSubsystemDescriptor(Cinfo cinfo)
{
id = cinfo.id;
#if UNITY_2020_2_OR_NEWER
providerType = cinfo.providerType;
subsystemTypeOverride = cinfo.subsystemTypeOverride;
#else
subsystemImplementationType = cinfo.subsystemImplementationType;
#endif
supportsMovingImages = cinfo.supportsMovingImages;
requiresPhysicalImageDimensions = cinfo.requiresPhysicalImageDimensions;
supportsMutableLibrary = cinfo.supportsMutableLibrary;
supportsImageValidation = cinfo.supportsImageValidation;
}
}
}