Skip to content

Commit 8a64b4f

Browse files
committed
Merge pull request #10319 from keveleigh/has-flag-rework
Introduce alternative to .HasFlag
1 parent 08bfe95 commit 8a64b4f

35 files changed

+365
-95
lines changed

Assets/MRTK/Core/Definitions/Devices/MixedRealityControllerVisualizationProfile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ private bool SettingContainsParameters(MixedRealityControllerVisualizationSettin
248248
{
249249
return setting.ControllerType != null &&
250250
setting.ControllerType.Type == controllerType &&
251-
setting.Handedness.HasFlag(hand) && setting.Handedness != Handedness.None;
251+
setting.Handedness.IsMaskSet(hand) && setting.Handedness != Handedness.None;
252252
}
253253
}
254254
}

Assets/MRTK/Core/Definitions/Devices/SupportedControllerType.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,23 @@ public enum SupportedControllerType
2828
GGVHand = 1 << 11,
2929
HPMotionController = 1 << 12
3030
}
31+
32+
/// <summary>
33+
/// Extension methods specific to the <see cref="SupportedControllerType"/> enum.
34+
/// </summary>
35+
public static class SupportedControllerTypeExtensions
36+
{
37+
/// <summary>
38+
/// Checks to determine if all bits in a provided mask are set.
39+
/// </summary>
40+
/// <param name="a"><see cref="SupportedControllerType"/> value.</param>
41+
/// <param name="b"><see cref="SupportedControllerType"/> mask.</param>
42+
/// <returns>
43+
/// True if all of the bits in the specified mask are set in the current value.
44+
/// </returns>
45+
public static bool IsMaskSet(this SupportedControllerType a, SupportedControllerType b)
46+
{
47+
return (a & b) == b;
48+
}
49+
}
3150
}

Assets/MRTK/Core/Definitions/SpatialAwareness/SpatialAwarenessSurfaceTypes.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,23 @@ public enum SpatialAwarenessSurfaceTypes
6363
/// </summary>
6464
Inferred = 1 << 7
6565
}
66+
67+
/// <summary>
68+
/// Extension methods specific to the <see cref="SpatialAwarenessSurfaceTypes"/> enum.
69+
/// </summary>
70+
public static class SpatialAwarenessSurfaceTypesExtensions
71+
{
72+
/// <summary>
73+
/// Checks to determine if all bits in a provided mask are set.
74+
/// </summary>
75+
/// <param name="a"><see cref="SpatialAwarenessSurfaceTypes"/> value.</param>
76+
/// <param name="b"><see cref="SpatialAwarenessSurfaceTypes"/> mask.</param>
77+
/// <returns>
78+
/// True if all of the bits in the specified mask are set in the current value.
79+
/// </returns>
80+
public static bool IsMaskSet(this SpatialAwarenessSurfaceTypes a, SpatialAwarenessSurfaceTypes b)
81+
{
82+
return (a & b) == b;
83+
}
84+
}
6685
}

Assets/MRTK/Core/Definitions/Utilities/AxisFlags.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,23 @@ public enum AxisFlags
1313
YAxis = 1 << 1,
1414
ZAxis = 1 << 2
1515
}
16+
17+
/// <summary>
18+
/// Extension methods specific to the <see cref="AxisFlags"/> enum.
19+
/// </summary>
20+
public static class AxisFlagsExtensions
21+
{
22+
/// <summary>
23+
/// Checks to determine if all bits in a provided mask are set.
24+
/// </summary>
25+
/// <param name="a"><see cref="AxisFlags"/> value.</param>
26+
/// <param name="b"><see cref="AxisFlags"/> mask.</param>
27+
/// <returns>
28+
/// True if all of the bits in the specified mask are set in the current value.
29+
/// </returns>
30+
public static bool IsMaskSet(this AxisFlags a, AxisFlags b)
31+
{
32+
return (a & b) == b;
33+
}
34+
}
1635
}

Assets/MRTK/Core/Definitions/Utilities/Handedness.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,23 @@ public enum Handedness : byte
3939
/// <remarks>Note, by default the specific hand actions will override settings mapped as both</remarks>
4040
Any = Other | Left | Right,
4141
}
42+
43+
/// <summary>
44+
/// Extension methods specific to the <see cref="Handedness"/> enum.
45+
/// </summary>
46+
public static class HandednessExtensions
47+
{
48+
/// <summary>
49+
/// Checks to determine if all bits in a provided mask are set.
50+
/// </summary>
51+
/// <param name="a"><see cref="Handedness"/> value.</param>
52+
/// <param name="b"><see cref="Handedness"/> mask.</param>
53+
/// <returns>
54+
/// True if all of the bits in the specified mask are set in the current value.
55+
/// </returns>
56+
public static bool IsMaskSet(this Handedness a, Handedness b)
57+
{
58+
return (a & b) == b;
59+
}
60+
}
4261
}

Assets/MRTK/Core/Definitions/Utilities/ManipulationHandFlags.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,23 @@ public enum ManipulationHandFlags
1212
OneHanded = 1 << 0,
1313
TwoHanded = 1 << 1,
1414
}
15+
16+
/// <summary>
17+
/// Extension methods specific to the <see cref="ManipulationHandFlags"/> enum.
18+
/// </summary>
19+
public static class ManipulationHandFlagsExtensions
20+
{
21+
/// <summary>
22+
/// Checks to determine if all bits in a provided mask are set.
23+
/// </summary>
24+
/// <param name="a"><see cref="ManipulationHandFlags"/> value.</param>
25+
/// <param name="b"><see cref="ManipulationHandFlags"/> mask.</param>
26+
/// <returns>
27+
/// True if all of the bits in the specified mask are set in the current value.
28+
/// </returns>
29+
public static bool IsMaskSet(this ManipulationHandFlags a, ManipulationHandFlags b)
30+
{
31+
return (a & b) == b;
32+
}
33+
}
1534
}

Assets/MRTK/Core/Definitions/Utilities/ManipulationProximityFlags.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,23 @@ public enum ManipulationProximityFlags
1212
Near = 1 << 0,
1313
Far = 1 << 1,
1414
}
15+
16+
/// <summary>
17+
/// Extension methods specific to the <see cref="ManipulationProximityFlags"/> enum.
18+
/// </summary>
19+
public static class ManipulationProximityFlagsExtensions
20+
{
21+
/// <summary>
22+
/// Checks to determine if all bits in a provided mask are set.
23+
/// </summary>
24+
/// <param name="a"><see cref="ManipulationProximityFlags"/> value.</param>
25+
/// <param name="b"><see cref="ManipulationProximityFlags"/> mask.</param>
26+
/// <returns>
27+
/// True if all of the bits in the specified mask are set in the current value.
28+
/// </returns>
29+
public static bool IsMaskSet(this ManipulationProximityFlags a, ManipulationProximityFlags b)
30+
{
31+
return (a & b) == b;
32+
}
33+
}
1534
}

Assets/MRTK/Core/Definitions/Utilities/SupportedPlatforms.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,23 @@ public enum SupportedUnityXRPipelines
3636
LegacyXR = 1 << 0,
3737
XRSDK = 1 << 1,
3838
}
39+
40+
/// <summary>
41+
/// Extension methods specific to the <see cref="SupportedUnityXRPipelines"/> enum.
42+
/// </summary>
43+
public static class SupportedUnityXRPipelinesExtensions
44+
{
45+
/// <summary>
46+
/// Checks to determine if all bits in a provided mask are set.
47+
/// </summary>
48+
/// <param name="a"><see cref="SupportedUnityXRPipelines"/> value.</param>
49+
/// <param name="b"><see cref="SupportedUnityXRPipelines"/> mask.</param>
50+
/// <returns>
51+
/// True if all of the bits in the specified mask are set in the current value.
52+
/// </returns>
53+
public static bool IsMaskSet(this SupportedUnityXRPipelines a, SupportedUnityXRPipelines b)
54+
{
55+
return (a & b) == b;
56+
}
57+
}
3958
}

Assets/MRTK/Core/Definitions/Utilities/TransformFlags.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,23 @@ public enum TransformFlags
1313
Rotate = 1 << 1,
1414
Scale = 1 << 2
1515
}
16+
17+
/// <summary>
18+
/// Extension methods specific to the <see cref="TransformFlags"/> enum.
19+
/// </summary>
20+
public static class TransformFlagsExtensions
21+
{
22+
/// <summary>
23+
/// Checks to determine if all bits in a provided mask are set.
24+
/// </summary>
25+
/// <param name="a"><see cref="TransformFlags"/> value.</param>
26+
/// <param name="b"><see cref="TransformFlags"/> mask.</param>
27+
/// <returns>
28+
/// True if all of the bits in the specified mask are set in the current value.
29+
/// </returns>
30+
public static bool IsMaskSet(this TransformFlags a, TransformFlags b)
31+
{
32+
return (a & b) == b;
33+
}
34+
}
1635
}

Assets/MRTK/Core/Inspectors/Profiles/MixedRealityControllerVisualizationProfileInspector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ private void RenderControllerList(SerializedProperty controllerList)
193193
if (hasValidType)
194194
{
195195
MixedRealityControllerAttribute controllerAttribute = MixedRealityControllerAttribute.Find(controllerType.Type);
196-
if (controllerAttribute != null && !controllerAttribute.SupportedUnityXRPipelines.HasFlag(xrPipelineUtility.SelectedPipeline))
196+
if (controllerAttribute != null && !controllerAttribute.SupportedUnityXRPipelines.IsMaskSet(xrPipelineUtility.SelectedPipeline))
197197
{
198198
continue;
199199
}

0 commit comments

Comments
 (0)