AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
RotatableObject.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using UnityEngine;
5 
6 #if UNITY_WSA && UNITY_2017_2_OR_NEWER
7 using System.Collections;
8 using UnityEngine.XR.WSA.Input;
9 #endif
10 
11 namespace HoloToolkit.Unity.InputModule.Examples.Grabbables
12 {
17  public class RotatableObject : BaseUsable
18  {
19 #if UNITY_WSA && UNITY_2017_2_OR_NEWER
20  private Vector3 touchPositionFromController = Vector3.zero;
21 #endif
22 
23  private BaseGrabbable baseGrabbable;
24 
25  protected override void OnEnable()
26  {
27  base.OnEnable();
28 
29 #if UNITY_WSA && UNITY_2017_2_OR_NEWER
30  InteractionManager.InteractionSourceUpdated += GetTouchPadPosition;
31 #endif
32 
33  if (baseGrabbable == null)
34  {
35  baseGrabbable = GetComponent<BaseGrabbable>();
36  }
37  }
38 
39  protected override void OnDisable()
40  {
41 #if UNITY_WSA && UNITY_2017_2_OR_NEWER
42  InteractionManager.InteractionSourceUpdated -= GetTouchPadPosition;
43 #endif
44 
45  base.OnDisable();
46  }
47 
52  protected override void UseStart()
53  {
54  if (baseGrabbable.GrabberPrimary != null)
55  {
56 #if UNITY_WSA && UNITY_2017_2_OR_NEWER
57  StartCoroutine(MakeRotate());
58 #endif
59  }
60  }
61 
62 #if UNITY_WSA && UNITY_2017_2_OR_NEWER
63  private IEnumerator MakeRotate()
64  {
65  while (UseState == UseStateEnum.Active && baseGrabbable.GrabberPrimary && touchPadPressed)
66  {
67  transform.Rotate(touchPositionFromController);
68  yield return 0;
69  }
70  GetComponent<Rigidbody>().angularVelocity = Vector3.zero;
71  yield return null;
72  }
73 
74  private void GetTouchPadPosition(InteractionSourceUpdatedEventArgs obj)
75  {
76  if (baseGrabbable.GrabberPrimary != null)
77  {
78  Debug.Log(" obj.state.source.handedness =====" + obj.state.source.handedness + " **** GrabberPriumary Handedness === " + baseGrabbable.GrabberPrimary.Handedness);
79  if (obj.state.source.handedness == baseGrabbable.GrabberPrimary.Handedness)
80  {
81  if (obj.state.touchpadTouched)
82  {
83  touchPositionFromController = obj.state.touchpadPosition;
84  touchPadPressed = true;
85  }
86  else
87  {
88  touchPadPressed = false;
89  }
90  }
91  }
92  }
93 
94  private bool touchPadPressed;
95 #endif
96  }
97 }
override void UseStart()
In the BaseUsable class that this class inherits from, UseStarted begins checking for usage after the...
//Intended Usage// Attach a "grabbable_x" script (a script that inherits from this) to any object tha...
A usable object is one that can be "used" or activated while being grabbed/carried A gun and a remote...
Definition: BaseUsable.cs:16
ForceRotate inherits from BaseUsable because the object to be manipulated must first be pick up (grab...