Skip to content

Commit af0228d

Browse files
wrapped the motion controller example XR APIs
1 parent de9ca57 commit af0228d

File tree

5 files changed

+52
-7
lines changed

5 files changed

+52
-7
lines changed

Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/BaseGrabber.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
using System;
55
using System.Collections.Generic;
66
using UnityEngine;
7+
8+
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
79
using UnityEngine.XR.WSA.Input;
10+
#endif
811

912
namespace HoloToolkit.Unity.InputModule.Examples.Grabbables
1013
{
@@ -17,7 +20,9 @@ public abstract class BaseGrabber : MonoBehaviour
1720
public event Action<BaseGrabber> OnGrabStateChange;
1821
public event Action<BaseGrabber> OnContactStateChange;
1922

23+
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
2024
public InteractionSourceHandedness Handedness { get { return handedness; } set { handedness = value; } }
25+
#endif
2126

2227
public List<BaseGrabbable> GrabbedObjects { get { return new List<BaseGrabbable>(grabbedObjects); } }
2328

@@ -75,8 +80,10 @@ public Transform GrabHandle
7580
private GrabStateEnum prevGrabState = GrabStateEnum.Inactive;
7681
private GrabStateEnum prevContactState = GrabStateEnum.Inactive;
7782

83+
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
7884
[SerializeField]
7985
protected InteractionSourceHandedness handedness;
86+
#endif
8087

8188
public bool IsGrabbing(BaseGrabbable grabbable)
8289
{

Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/BaseUsable.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
using UnityEngine;
5+
6+
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
57
using UnityEngine.XR.WSA.Input;
8+
#endif
69

710
namespace HoloToolkit.Unity.InputModule.Examples.Grabbables
811
{
@@ -12,6 +15,7 @@ namespace HoloToolkit.Unity.InputModule.Examples.Grabbables
1215
/// </summary>
1316
public abstract class BaseUsable : MonoBehaviour
1417
{
18+
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
1519
[SerializeField]
1620
private InteractionSourceHandedness handedness;
1721

@@ -20,9 +24,11 @@ public abstract class BaseUsable : MonoBehaviour
2024
/// </summary>
2125
[SerializeField]
2226
private InteractionSourcePressType pressType;
27+
#endif
2328

2429
private UseStateEnum state;
2530

31+
2632
public UseStateEnum UseState
2733
{
2834
get { return state; }
@@ -42,16 +48,21 @@ protected virtual void UseEnd()
4248

4349
protected virtual void OnEnable()
4450
{
51+
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
4552
InteractionManager.InteractionSourcePressed += UseInputStart;
4653
InteractionManager.InteractionSourceReleased += UseInputEnd;
54+
#endif
4755
}
4856

4957
protected virtual void OnDisable()
5058
{
59+
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
5160
InteractionManager.InteractionSourcePressed -= UseInputStart;
5261
InteractionManager.InteractionSourceReleased -= UseInputEnd;
62+
#endif
5363
}
5464

65+
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
5566
private void UseInputStart(InteractionSourcePressedEventArgs obj)
5667
{
5768
if (/*obj.pressType == pressType && (*/handedness == InteractionSourceHandedness.Unknown || handedness == obj.state.source.handedness)
@@ -73,5 +84,6 @@ private void UseInputEnd(InteractionSourceReleasedEventArgs obj)
7384
UseEnd();
7485
}
7586
}
87+
#endif
7688
}
7789
}

Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/ExtensionMethod.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4+
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
45
using UnityEngine;
56
using HoloToolkit.Unity.InputModule.Examples.Grabbables;
67
using UnityEngine.XR.WSA.Input;
@@ -27,3 +28,4 @@ public static ControllerReleaseData GetThrowReleasedVelocityAndAngularVelocity(t
2728
return new ControllerReleaseData(setVel, angVel);
2829
}
2930
}
31+
#endif

Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/Grabber.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
using UnityEngine;
5+
6+
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
57
using UnityEngine.XR.WSA.Input;
8+
#endif
69

710
namespace HoloToolkit.Unity.InputModule.Examples.Grabbables
811
{
@@ -12,21 +15,34 @@ namespace HoloToolkit.Unity.InputModule.Examples.Grabbables
1215
/// </summary>
1316
public class Grabber : BaseGrabber
1417
{
18+
[SerializeField]
19+
private LayerMask grabbableLayers = ~0;
20+
21+
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
22+
[SerializeField]
23+
private InteractionSourcePressType pressType;
24+
#endif
25+
1526
///Subscribe GrabStart and GrabEnd to InputEvents for GripPressed
1627
protected override void OnEnable()
1728
{
1829
base.OnEnable();
30+
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
1931
InteractionManager.InteractionSourcePressed += InteractionSourcePressed;
2032
InteractionManager.InteractionSourceReleased += InteractionSourceReleased;
33+
#endif
2134
}
2235

2336
protected override void OnDisable()
2437
{
38+
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
2539
InteractionManager.InteractionSourcePressed -= InteractionSourcePressed;
2640
InteractionManager.InteractionSourceReleased -= InteractionSourceReleased;
41+
#endif
2742
base.OnDisable();
2843
}
2944

45+
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
3046
private void InteractionSourcePressed(InteractionSourcePressedEventArgs obj)
3147
{
3248
if (obj.pressType == pressType && obj.state.source.handedness == handedness)
@@ -43,6 +59,7 @@ private void InteractionSourceReleased(InteractionSourceReleasedEventArgs obj)
4359
GrabEnd();
4460
}
4561
}
62+
#endif
4663

4764
/// <summary>
4865
/// Controller grabbers find available grabbable objects via triggers
@@ -96,6 +113,7 @@ protected virtual void OnTriggerExit(Collider other)
96113
RemoveContact(bg);
97114
}
98115

116+
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
99117
public bool TrySetThrowableObject(BaseGrabbable grabbable, InteractionSourcePose poseInfo)
100118
{
101119
if (grabbable == null)
@@ -124,11 +142,6 @@ public bool TrySetThrowableObject(BaseGrabbable grabbable, InteractionSourcePose
124142
grabbable.GetComponent<BaseThrowable>().LatestControllerThrowAngularVelocity = controlReleaseData.AngleVelocity;
125143
return true;
126144
}
127-
128-
[SerializeField]
129-
private LayerMask grabbableLayers = ~0;
130-
131-
[SerializeField]
132-
private InteractionSourcePressType pressType;
145+
#endif
133146
}
134147
}

Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/RotatableObject.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
using System.Collections;
54
using UnityEngine;
5+
6+
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
7+
using System.Collections;
68
using UnityEngine.XR.WSA.Input;
9+
#endif
710

811
namespace HoloToolkit.Unity.InputModule.Examples.Grabbables
912
{
@@ -20,7 +23,9 @@ protected override void OnEnable()
2023
{
2124
base.OnEnable();
2225

26+
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
2327
InteractionManager.InteractionSourceUpdated += GetTouchPadPosition;
28+
#endif
2429

2530
if (baseGrabbable == null)
2631
{
@@ -30,7 +35,9 @@ protected override void OnEnable()
3035

3136
protected override void OnDisable()
3237
{
38+
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
3339
InteractionManager.InteractionSourceUpdated -= GetTouchPadPosition;
40+
#endif
3441

3542
base.OnDisable();
3643
}
@@ -43,10 +50,13 @@ protected override void UseStart()
4350
{
4451
if (baseGrabbable.GrabberPrimary != null)
4552
{
53+
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
4654
StartCoroutine(MakeRotate());
55+
#endif
4756
}
4857
}
4958

59+
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
5060
private IEnumerator MakeRotate()
5161
{
5262
while (UseState == UseStateEnum.Active && baseGrabbable.GrabberPrimary && touchPadPressed)
@@ -79,5 +89,6 @@ private void GetTouchPadPosition(InteractionSourceUpdatedEventArgs obj)
7989
}
8090

8191
private bool touchPadPressed;
92+
#endif
8293
}
8394
}

0 commit comments

Comments
 (0)