1
1
// Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
2
+ // Licensed under the MIT License.
3
3
4
4
using Microsoft . MixedReality . Toolkit . Input ;
5
5
using Microsoft . MixedReality . Toolkit . Utilities ;
6
- using UnityEngine ;
6
+ using System ;
7
7
using System . Collections . Generic ;
8
8
using Unity . Profiling ;
9
- using System ;
9
+ using UnityEngine ;
10
10
11
11
#if LEAPMOTIONCORE_PRESENT
12
12
using Leap ;
@@ -55,27 +55,27 @@ public bool CheckCapability(MixedRealityCapability capability)
55
55
56
56
#if LEAPMOTIONCORE_PRESENT
57
57
/// <summary>
58
- /// The profile that contains settings for the Leap Motion Device Manager input data provider. This profile is nested under
58
+ /// The profile that contains settings for the Leap Motion Device Manager input data provider. This profile is nested under
59
59
/// Input > Input Data Providers > Leap Motion Device Manager in the MixedRealityToolkit object in the hierarchy.
60
60
/// </summary>
61
61
public LeapMotionDeviceManagerProfile SettingsProfile => ConfigurationProfile as LeapMotionDeviceManagerProfile ;
62
62
63
63
/// <summary>
64
- /// The LeapServiceProvider is added to the scene at runtime in OnEnable.
64
+ /// The LeapServiceProvider is added to the scene at runtime in OnEnable.
65
65
/// </summary>
66
66
public LeapServiceProvider LeapMotionServiceProvider { get ; protected set ; }
67
67
68
68
/// <summary>
69
69
/// The distance between the index finger tip and the thumb tip required to enter the pinch/air tap selection gesture.
70
- /// The pinch gesture enter will be registered for all values less than the EnterPinchDistance. The default EnterPinchDistance value is 0.02 and must be between 0.015 and 0.1.
70
+ /// The pinch gesture enter will be registered for all values less than the EnterPinchDistance. The default EnterPinchDistance value is 0.02 and must be between 0.015 and 0.1.
71
71
/// </summary>
72
- private float enterPinchDistance => SettingsProfile . EnterPinchDistance ;
72
+ private float EnterPinchDistance => SettingsProfile . EnterPinchDistance ;
73
73
74
74
/// <summary>
75
75
/// The distance between the index finger tip and the thumb tip required to exit the pinch/air tap gesture.
76
- /// The pinch gesture exit will be registered for all values greater than the ExitPinchDistance. The default ExitPinchDistance value is 0.05 and must be between 0.015 and 0.1.
76
+ /// The pinch gesture exit will be registered for all values greater than the ExitPinchDistance. The default ExitPinchDistance value is 0.05 and must be between 0.015 and 0.1.
77
77
/// </summary>
78
- private float exitPinchDistance => SettingsProfile . ExitPinchDistance ;
78
+ private float ExitPinchDistance => SettingsProfile . ExitPinchDistance ;
79
79
80
80
/// <summary>
81
81
/// If true, the leap motion controller is connected and detected.
@@ -90,21 +90,21 @@ public bool CheckCapability(MixedRealityCapability capability)
90
90
/// <summary>
91
91
/// List of hands that are currently in frame and detected by the leap motion controller. If there are no hands in the current frame, this list will be empty.
92
92
/// </summary>
93
- private List < Hand > currentHandsDetectedByLeap => LeapMotionServiceProvider . CurrentFrame . Hands ;
93
+ private List < Hand > CurrentHandsDetectedByLeap => LeapMotionServiceProvider . CurrentFrame . Hands ;
94
94
95
95
// This value can only be set in the profile, the default is LeapControllerOrientation.Headset.
96
- private LeapControllerOrientation leapControllerOrientation => SettingsProfile . LeapControllerOrientation ;
96
+ private LeapControllerOrientation LeapControllerOrientation => SettingsProfile . LeapControllerOrientation ;
97
97
98
98
/// <summary>
99
99
/// Adds an offset to the game object with LeapServiceProvider attached. This offset is only applied if the leapControllerOrientation
100
- /// is LeapControllerOrientation.Desk and is necessary for the hand to appear in front of the main camera. If the leap controller is on the
101
- /// desk, the LeapServiceProvider is added to the scene instead of the LeapXRServiceProvider. The anchor point for the position of the leap hands is
100
+ /// is LeapControllerOrientation.Desk and is necessary for the hand to appear in front of the main camera. If the leap controller is on the
101
+ /// desk, the LeapServiceProvider is added to the scene instead of the LeapXRServiceProvider. The anchor point for the position of the leap hands is
102
102
/// the position of the game object with the LeapServiceProvider attached.
103
103
/// </summary>
104
- private Vector3 leapHandsOffset => SettingsProfile . LeapControllerOffset ;
104
+ private Vector3 LeapHandsOffset => SettingsProfile . LeapControllerOffset ;
105
105
106
106
// If the Leap Controller Orientation is the Headset, controller offset settings will be exposed in the inspector while using the LeapXRServiceProvider
107
- private LeapVRDeviceOffsetMode leapVRDeviceOffsetMode => SettingsProfile . LeapVRDeviceOffsetMode ;
107
+ private LeapVRDeviceOffsetMode LeapVRDeviceOffsetMode => SettingsProfile . LeapVRDeviceOffsetMode ;
108
108
109
109
/// <summary>
110
110
/// Dictionary to capture all active leap motion hands detected.
@@ -121,7 +121,7 @@ public override void Enable()
121
121
{
122
122
base . Enable ( ) ;
123
123
124
- if ( leapControllerOrientation == LeapControllerOrientation . Headset )
124
+ if ( LeapControllerOrientation == LeapControllerOrientation . Headset )
125
125
{
126
126
// As of the Unity Plugin (>V5.0.0), the leap service provider needs to know what is the main camera,
127
127
// it will pick this up from the MainCameraProvider. This needs to be done before the LeapXRServiceProvider is created
@@ -130,26 +130,26 @@ public override void Enable()
130
130
MainCameraProvider . mainCamera = CameraCache . Main ;
131
131
#endif
132
132
// If the leap controller is mounted on a headset then add the LeapXRServiceProvider to the scene
133
- LeapMotionServiceProvider = CameraCache . Main . gameObject . AddComponent < LeapXRServiceProvider > ( ) ;
134
-
133
+ LeapXRServiceProvider leapXRServiceProvider ; // This is a different type than the LeapMotionServiceProvider property for access to specific settings below.
134
+ LeapMotionServiceProvider = leapXRServiceProvider = CameraCache . Main . gameObject . AddComponent < LeapXRServiceProvider > ( ) ;
135
+
135
136
// Allow modification of VR specific offset modes if the leapControllerOrientation is Headset
136
137
// These settings mirror the modification of the properties exposed in the inspector within the LeapXRServiceProvider attached
137
138
// to the main camera
138
- if ( leapVRDeviceOffsetMode == LeapVRDeviceOffsetMode . ManualHeadOffset )
139
+ if ( LeapVRDeviceOffsetMode == LeapVRDeviceOffsetMode . ManualHeadOffset )
139
140
{
140
- // Change the offset mode before setting the properties
141
+ // Change the offset mode before setting the properties
141
142
leapXRServiceProvider . deviceOffsetMode = LeapXRServiceProvider . DeviceOffsetMode . ManualHeadOffset ;
142
143
143
144
leapXRServiceProvider . deviceOffsetYAxis = SettingsProfile . LeapVRDeviceOffsetY ;
144
145
leapXRServiceProvider . deviceOffsetZAxis = SettingsProfile . LeapVRDeviceOffsetZ ;
145
146
leapXRServiceProvider . deviceTiltXAxis = SettingsProfile . LeapVRDeviceOffsetTiltX ;
146
147
}
147
- else if ( leapVRDeviceOffsetMode == LeapVRDeviceOffsetMode . Transform )
148
+ else if ( LeapVRDeviceOffsetMode == LeapVRDeviceOffsetMode . Transform )
148
149
{
149
150
if ( SettingsProfile . LeapVRDeviceOrigin != null )
150
151
{
151
152
leapXRServiceProvider . deviceOffsetMode = LeapXRServiceProvider . DeviceOffsetMode . Transform ;
152
-
153
153
leapXRServiceProvider . deviceOrigin = SettingsProfile . LeapVRDeviceOrigin ;
154
154
}
155
155
else
@@ -159,7 +159,7 @@ public override void Enable()
159
159
}
160
160
}
161
161
162
- if ( leapControllerOrientation == LeapControllerOrientation . Desk )
162
+ if ( LeapControllerOrientation == LeapControllerOrientation . Desk )
163
163
{
164
164
// Create a separate gameobject if the leap controller is on the desk
165
165
GameObject leapProvider = new GameObject ( "LeapProvider" ) ;
@@ -171,7 +171,7 @@ public override void Enable()
171
171
leapProvider . transform . parent = CameraCache . Main . transform ;
172
172
173
173
// Apply hand position offset, an offset is required to render the hands in view and in front of the camera
174
- LeapMotionServiceProvider . transform . position += leapHandsOffset ;
174
+ LeapMotionServiceProvider . transform . position += LeapHandsOffset ;
175
175
}
176
176
177
177
// Add the attachment hands to the scene for the purpose of getting the tracking state of each hand and joint positions
@@ -208,12 +208,12 @@ public override void Disable()
208
208
if ( LeapMotionServiceProvider != null )
209
209
{
210
210
// Destroy the LeapProvider GameObject if the controller orientation is the desk
211
- if ( leapControllerOrientation == LeapControllerOrientation . Desk )
211
+ if ( LeapControllerOrientation == LeapControllerOrientation . Desk )
212
212
{
213
213
GameObject . Destroy ( LeapMotionServiceProvider . gameObject ) ;
214
214
}
215
215
// Destroy the LeapXRServiceProvider attached to the main camera if the controller orientation is headset
216
- else if ( leapControllerOrientation == LeapControllerOrientation . Headset )
216
+ else if ( LeapControllerOrientation == LeapControllerOrientation . Headset )
217
217
{
218
218
GameObject . Destroy ( LeapMotionServiceProvider ) ;
219
219
}
@@ -235,8 +235,8 @@ private void OnHandDetected(Handedness handedness)
235
235
var leapHand = new LeapMotionArticulatedHand ( TrackingState . Tracked , handedness , inputSource ) ;
236
236
237
237
// Set pinch thresholds
238
- leapHand . HandDefinition . EnterPinchDistance = enterPinchDistance ;
239
- leapHand . HandDefinition . ExitPinchDistance = exitPinchDistance ;
238
+ leapHand . HandDefinition . EnterPinchDistance = EnterPinchDistance ;
239
+ leapHand . HandDefinition . ExitPinchDistance = ExitPinchDistance ;
240
240
241
241
// Set the leap attachment hand to the corresponding handedness
242
242
if ( handedness == Handedness . Left )
@@ -247,7 +247,7 @@ private void OnHandDetected(Handedness handedness)
247
247
{
248
248
leapHand . SetAttachmentHands ( rightAttachmentHand , LeapMotionServiceProvider ) ;
249
249
}
250
-
250
+
251
251
// Set the pointers for an articulated hand to the leap hand
252
252
foreach ( var pointer in pointers )
253
253
{
@@ -289,7 +289,7 @@ private void UpdateLeapTrackedHands(bool isLeftTracked, bool isRightTracked)
289
289
if ( isLeftTracked && ! trackedHands . ContainsKey ( Handedness . Left ) )
290
290
{
291
291
OnHandDetected ( Handedness . Left ) ;
292
- }
292
+ }
293
293
else if ( ! isLeftTracked && trackedHands . ContainsKey ( Handedness . Left ) )
294
294
{
295
295
OnHandDetectionLost ( Handedness . Left ) ;
@@ -316,7 +316,7 @@ public override void Update()
316
316
if ( IsLeapConnected )
317
317
{
318
318
// if the number of tracked hands in frame has changed
319
- if ( currentHandsDetectedByLeap . Count != trackedHands . Count )
319
+ if ( CurrentHandsDetectedByLeap . Count != trackedHands . Count )
320
320
{
321
321
UpdateLeapTrackedHands ( leftAttachmentHand . isTracked , rightAttachmentHand . isTracked ) ;
322
322
}
0 commit comments