55using Microsoft . MixedReality . Toolkit . Input ;
66
77#if UNITY_WSA
8- using UnityEngine ;
98using UnityEngine . XR . WSA . Input ;
10- #endif
11-
12- #if WINDOWS_UWP
13- using Microsoft . MixedReality . Toolkit . Windows . Utilities ;
9+ #if WINDOWS_UWP || DOTNETWINRT_PRESENT
1410using System ;
1511using System . Collections . Generic ;
12+ using UnityEngine ;
13+ #if WINDOWS_UWP
14+ using Windows . Foundation . Metadata ;
1615using Windows . Perception ;
1716using Windows . Perception . People ;
1817using Windows . UI . Input . Spatial ;
18+ #elif DOTNETWINRT_PRESENT
19+ using Microsoft . Windows . Foundation . Metadata ;
20+ using Microsoft . Windows . Perception ;
21+ using Microsoft . Windows . Perception . People ;
22+ using Microsoft . Windows . UI . Input . Spatial ;
1923#endif
24+ #endif // WINDOWS_UWP || DOTNETWINRT_PRESENT
25+ #endif // UNITY_WSA
2026
2127namespace Microsoft . MixedReality . Toolkit . WindowsMixedReality . Input
2228{
@@ -34,6 +40,9 @@ public class WindowsMixedRealityArticulatedHand : BaseWindowsMixedRealitySource,
3440 public WindowsMixedRealityArticulatedHand ( TrackingState trackingState , Handedness controllerHandedness , IMixedRealityInputSource inputSource = null , MixedRealityInteractionMapping [ ] interactions = null )
3541 : base ( trackingState , controllerHandedness , inputSource , interactions )
3642 {
43+ #if ( UNITY_WSA && DOTNETWINRT_PRESENT ) || WINDOWS_UWP
44+ articulatedHandApiAvailable = ApiInformation . IsMethodPresent ( "Windows.UI.Input.Spatial.SpatialInteractionSourceState" , "TryGetHandPose" ) ;
45+ #endif
3746 }
3847
3948 /// <summary>
@@ -54,7 +63,7 @@ public WindowsMixedRealityArticulatedHand(TrackingState trackingState, Handednes
5463 /// <inheritdoc/>
5564 public bool TryGetJoint ( TrackedHandJoint joint , out MixedRealityPose pose )
5665 {
57- #if WINDOWS_UWP
66+ #if ( UNITY_WSA && DOTNETWINRT_PRESENT ) || WINDOWS_UWP
5867 return unityJointPoses . TryGetValue ( joint , out pose ) ;
5968#else
6069 pose = MixedRealityPose . ZeroIdentity ;
@@ -69,7 +78,7 @@ public override bool IsInPointingPose
6978 get
7079 {
7180 bool valid = true ;
72- #if WINDOWS_UWP
81+ #if ( UNITY_WSA && DOTNETWINRT_PRESENT ) || WINDOWS_UWP
7382 Vector3 palmNormal = unityJointOrientations [ ( int ) HandJointKind . Palm ] * ( - 1 * Vector3 . up ) ;
7483 if ( CursorBeamBackwardTolerance >= 0 )
7584 {
@@ -86,17 +95,16 @@ public override bool IsInPointingPose
8695 valid = false ;
8796 }
8897 }
89- #endif // WINDOWS_UWP
98+ #endif // (UNITY_WSA && DOTNETWINRT_PRESENT) || WINDOWS_UWP
9099 return valid ;
91100 }
92101 }
93102
94103#if UNITY_WSA
104+ #if WINDOWS_UWP || DOTNETWINRT_PRESENT
95105 private MixedRealityPose currentIndexPose = MixedRealityPose . ZeroIdentity ;
96106
97- private readonly HandRay handRay = new HandRay ( ) ;
98-
99- #if WINDOWS_UWP
107+ private SpatialInteractionManager spatialInteractionManager = null ;
100108 private SpatialInteractionManager SpatialInteractionManager
101109 {
102110 get
@@ -113,15 +121,18 @@ private SpatialInteractionManager SpatialInteractionManager
113121 }
114122 }
115123
116- private SpatialInteractionManager spatialInteractionManager = null ;
124+ #if WINDOWS_UWP
117125 private HandMeshObserver handMeshObserver = null ;
118126 private int [ ] handMeshTriangleIndices = null ;
119127 private bool hasRequestedHandMeshObserver = false ;
120128 private Vector2 [ ] handMeshUVs ;
129+ #endif // WINDOWS_UWP
121130
122131 private readonly float CursorBeamBackwardTolerance = 0.5f ;
123132 private readonly float CursorBeamUpTolerance = 0.8f ;
124- #endif // WINDOWS_UWP
133+
134+ private readonly bool articulatedHandApiAvailable = false ;
135+ #endif // WINDOWS_UWP || DOTNETWINRT_PRESENT
125136
126137 #region Update data functions
127138
@@ -194,19 +205,19 @@ private async void SetHandMeshObserver(SpatialInteractionSourceState sourceState
194205 {
195206 handMeshObserver = await sourceState . Source . TryCreateHandMeshObserverAsync ( ) ;
196207 }
197- #endif
208+ #endif // WINDOWS_UWP
198209
199210 /// <summary>
200211 /// Update the hand data from the device.
201212 /// </summary>
202213 /// <param name="interactionSourceState">The InteractionSourceState retrieved from the platform.</param>
203214 private void UpdateHandData ( InteractionSourceState interactionSourceState )
204215 {
205- #if WINDOWS_UWP
216+ #if WINDOWS_UWP || DOTNETWINRT_PRESENT
206217 // Articulated hand support is only present in the 18362 version and beyond Windows
207218 // SDK (which contains the V8 drop of the Universal API Contract). In particular,
208219 // the HandPose related APIs are only present on this version and above.
209- if ( ! WindowsApiChecker . UniversalApiContractV8_IsAvailable )
220+ if ( ! articulatedHandApiAvailable )
210221 {
211222 return ;
212223 }
@@ -219,6 +230,7 @@ private void UpdateHandData(InteractionSourceState interactionSourceState)
219230 {
220231 HandPose handPose = sourceState . TryGetHandPose ( ) ;
221232
233+ #if WINDOWS_UWP
222234 if ( CoreServices . InputSystem . InputSystemProfile . HandTrackingProfile . EnableHandMeshVisualization )
223235 {
224236 // Accessing the hand mesh data involves copying quite a bit of data, so only do it if application requests it.
@@ -301,6 +313,7 @@ private void UpdateHandData(InteractionSourceState interactionSourceState)
301313 handMeshObserver = null ;
302314 }
303315 }
316+ #endif // WINDOWS_UWP
304317
305318 if ( handPose != null && handPose . TryGetJoints ( WindowsMixedRealityUtilities . SpatialCoordinateSystem , jointIndices , jointPoses ) )
306319 {
@@ -334,12 +347,12 @@ private void UpdateHandData(InteractionSourceState interactionSourceState)
334347 }
335348 }
336349 }
337- #endif // WINDOWS_UWP
350+ #endif // WINDOWS_UWP || DOTNETWINRT_PRESENT
338351 }
339352
340353 private void UpdateIndexFingerData ( InteractionSourceState interactionSourceState , MixedRealityInteractionMapping interactionMapping )
341354 {
342- #if WINDOWS_UWP
355+ #if WINDOWS_UWP || DOTNETWINRT_PRESENT
343356 UpdateCurrentIndexPose ( ) ;
344357
345358 // Update the interaction data source
@@ -351,12 +364,12 @@ private void UpdateIndexFingerData(InteractionSourceState interactionSourceState
351364 // Raise input system event if it's enabled
352365 CoreServices . InputSystem ? . RaisePoseInputChanged ( InputSource , ControllerHandedness , interactionMapping . MixedRealityInputAction , currentIndexPose ) ;
353366 }
354- #endif // WINDOWS_UWP
367+ #endif // WINDOWS_UWP || DOTNETWINRT_PRESENT
355368 }
356369
357370 #endregion Update data functions
358371
359- #if WINDOWS_UWP
372+ #if WINDOWS_UWP || DOTNETWINRT_PRESENT
360373 private static readonly HandJointKind [ ] jointIndices = new HandJointKind [ ]
361374 {
362375 HandJointKind . Palm ,
@@ -446,7 +459,7 @@ protected void UpdateCurrentIndexPose()
446459
447460 #endregion Private InputSource Helpers
448461
449- #endif // WINDOWS_UWP
462+ #endif // WINDOWS_UWP || DOTNETWINRT_PRESENT
450463#endif // UNITY_WSA
451464 }
452465}
0 commit comments