22// Licensed under the MIT License. See LICENSE in the project root for license information.
33
44using UnityEngine ;
5+ #if UNITY_2017_2_OR_NEWER
6+ using UnityEngine . XR . WSA . Input ;
7+ #else
8+ using UnityEngine . VR . WSA . Input ;
9+ #endif
510
611namespace HoloToolkit . Unity . InputModule
712{
@@ -11,7 +16,8 @@ namespace HoloToolkit.Unity.InputModule
1116 /// </summary>
1217 public class MotionControllerInfo
1318 {
14- public GameObject ControllerParent ;
19+ public readonly GameObject ControllerParent ;
20+ public readonly InteractionSourceHandedness Handedness ;
1521
1622 private GameObject home ;
1723 private Transform homePressed ;
@@ -44,6 +50,7 @@ public class MotionControllerInfo
4450 private Transform touchpadTouchYMin ;
4551 private Transform touchpadTouchYMax ;
4652 private GameObject touchpadTouchVisualizer ;
53+ private GameObject pointingPose ;
4754
4855 // These values are used to determine if a button's state has changed.
4956 private bool wasGrasped ;
@@ -56,14 +63,94 @@ public class MotionControllerInfo
5663 private Vector2 lastTouchpadPosition ;
5764 private double lastSelectPressedAmount ;
5865
66+ public MotionControllerInfo ( GameObject controllerParent , InteractionSourceHandedness handedness )
67+ {
68+ ControllerParent = controllerParent ;
69+ Handedness = handedness ;
70+ }
71+
72+ public enum ControllerElementEnum
73+ {
74+ // Controller button elements
75+ Home ,
76+ Menu ,
77+ Grasp ,
78+ Thumbstick ,
79+ Select ,
80+ Touchpad ,
81+ // Controller body elements & poses
82+ PointingPose
83+ }
84+
85+ public bool TryGetElement ( ControllerElementEnum element , out Transform elementTransform )
86+ {
87+ switch ( element )
88+ {
89+ // control elements
90+ case ControllerElementEnum . Home :
91+ if ( home != null )
92+ {
93+ elementTransform = home . transform ;
94+ return true ;
95+ }
96+ break ;
97+ case ControllerElementEnum . Menu :
98+ if ( menu != null )
99+ {
100+ elementTransform = menu . transform ;
101+ return true ;
102+ }
103+ break ;
104+ case ControllerElementEnum . Select :
105+ if ( select != null )
106+ {
107+ elementTransform = select . transform ;
108+ return true ;
109+ }
110+ break ;
111+ case ControllerElementEnum . Grasp :
112+ if ( grasp != null )
113+ {
114+ elementTransform = grasp . transform ;
115+ return true ;
116+ }
117+ break ;
118+ case ControllerElementEnum . Thumbstick :
119+ if ( thumbstickPress != null )
120+ {
121+ elementTransform = thumbstickPress . transform ;
122+ return true ;
123+ }
124+ break ;
125+ case ControllerElementEnum . Touchpad :
126+ if ( touchpadPress != null )
127+ {
128+ elementTransform = touchpadPress . transform ;
129+ return true ;
130+ }
131+ break ;
132+ // body elements & poses
133+ case ControllerElementEnum . PointingPose :
134+ if ( pointingPose != null )
135+ {
136+ elementTransform = pointingPose . transform ;
137+ return true ;
138+ }
139+ break ;
140+ }
141+
142+ elementTransform = null ;
143+ return false ;
144+ }
145+
59146 /// <summary>
60147 /// Iterates through the Transform array to find specifically named GameObjects.
61148 /// These GameObjects specify the animation bounds and the GameObject to modify for button,
62149 /// thumbstick, and touchpad animation.
63150 /// </summary>
64151 /// <param name="childTransforms">The transforms of the glTF model.</param>
65152 /// <param name="visualizerScript">The script containing references to any objects to spawn.</param>
66- public void LoadInfo ( Transform [ ] childTransforms , MotionControllerVisualizer visualizerScript )
153+ public void LoadInfo ( Transform [ ] childTransforms )
67154 {
68155 foreach ( Transform child in childTransforms )
69156 {
@@ -75,6 +162,12 @@ public void LoadInfo(Transform[] childTransforms, MotionControllerVisualizer vis
75162 // visualizer.
76163 switch ( child . name . ToLower ( ) )
77164 {
165+ case "touch" :
166+ touchpadTouchVisualizer = MotionControllerVisualizer . Instance . SpawnTouchpadVisualizer ( child ) ;
167+ break ;
168+ case "pointing_pose" :
169+ pointingPose = child . gameObject ;
170+ break ;
78171 case "pressed" :
79172 switch ( child . parent . name . ToLower ( ) )
80173 {
@@ -190,9 +283,6 @@ public void LoadInfo(Transform[] childTransforms, MotionControllerVisualizer vis
190283 break ;
191284 }
192285 break ;
193- case "touch" :
194- touchpadTouchVisualizer = visualizerScript . SpawnTouchpadVisualizer ( child ) ;
195- break ;
196286 }
197287 }
198288 }
@@ -289,5 +379,14 @@ private void SetLocalPositionAndRotation(GameObject buttonGameObject, Transform
289379 buttonGameObject . transform . localPosition = newTransform . localPosition ;
290380 buttonGameObject . transform . localRotation = newTransform . localRotation ;
291381 }
382+
383+ public void SetRenderersVisible ( bool visible )
384+ {
385+ MeshRenderer [ ] renderers = ControllerParent . GetComponentsInChildren < MeshRenderer > ( ) ;
386+ for ( int i = 0 ; i < renderers . Length ; i ++ )
387+ {
388+ renderers [ i ] . enabled = visible ;
389+ }
390+ }
292391 }
293392}
0 commit comments