22// Licensed under the MIT License. See LICENSE in the project root for license information.
33
44using UnityEngine ;
5+ using UnityEngine . XR . WSA . Input ;
56
67namespace HoloToolkit . Unity . InputModule
78{
@@ -11,7 +12,8 @@ namespace HoloToolkit.Unity.InputModule
1112 /// </summary>
1213 public class MotionControllerInfo
1314 {
14- public GameObject ControllerParent ;
15+ public readonly GameObject ControllerParent ;
16+ public readonly InteractionSourceHandedness Handedness ;
1517
1618 private GameObject home ;
1719 private Transform homePressed ;
@@ -44,6 +46,7 @@ public class MotionControllerInfo
4446 private Transform touchpadTouchYMin ;
4547 private Transform touchpadTouchYMax ;
4648 private GameObject touchpadTouchVisualizer ;
49+ private GameObject pointingPose ;
4750
4851 // These values are used to determine if a button's state has changed.
4952 private bool wasGrasped ;
@@ -56,14 +59,94 @@ public class MotionControllerInfo
5659 private Vector2 lastTouchpadPosition ;
5760 private double lastSelectPressedAmount ;
5861
62+ public MotionControllerInfo ( GameObject controllerParent , InteractionSourceHandedness handedness )
63+ {
64+ ControllerParent = controllerParent ;
65+ Handedness = handedness ;
66+ }
67+
68+ public enum ControllerElementEnum
69+ {
70+ // Controller button elements
71+ Home ,
72+ Menu ,
73+ Grasp ,
74+ Thumbstick ,
75+ Select ,
76+ Touchpad ,
77+ // Controller body elements & poses
78+ PointingPose
79+ }
80+
81+ public bool TryGetElement ( ControllerElementEnum element , out Transform elementTransform )
82+ {
83+ switch ( element )
84+ {
85+ // control elements
86+ case ControllerElementEnum . Home :
87+ if ( home != null )
88+ {
89+ elementTransform = home . transform ;
90+ return true ;
91+ }
92+ break ;
93+ case ControllerElementEnum . Menu :
94+ if ( menu != null )
95+ {
96+ elementTransform = menu . transform ;
97+ return true ;
98+ }
99+ break ;
100+ case ControllerElementEnum . Select :
101+ if ( select != null )
102+ {
103+ elementTransform = select . transform ;
104+ return true ;
105+ }
106+ break ;
107+ case ControllerElementEnum . Grasp :
108+ if ( grasp != null )
109+ {
110+ elementTransform = grasp . transform ;
111+ return true ;
112+ }
113+ break ;
114+ case ControllerElementEnum . Thumbstick :
115+ if ( thumbstickPress != null )
116+ {
117+ elementTransform = thumbstickPress . transform ;
118+ return true ;
119+ }
120+ break ;
121+ case ControllerElementEnum . Touchpad :
122+ if ( touchpadPress != null )
123+ {
124+ elementTransform = touchpadPress . transform ;
125+ return true ;
126+ }
127+ break ;
128+ // body elements & poses
129+ case ControllerElementEnum . PointingPose :
130+ if ( pointingPose != null )
131+ {
132+ elementTransform = pointingPose . transform ;
133+ return true ;
134+ }
135+ break ;
136+ }
137+
138+ elementTransform = null ;
139+ return false ;
140+ }
141+
59142 /// <summary>
60143 /// Iterates through the Transform array to find specifically named GameObjects.
61144 /// These GameObjects specify the animation bounds and the GameObject to modify for button,
62145 /// thumbstick, and touchpad animation.
63146 /// </summary>
64147 /// <param name="childTransforms">The transforms of the glTF model.</param>
65148 /// <param name="visualizerScript">The script containing references to any objects to spawn.</param>
66- public void LoadInfo ( Transform [ ] childTransforms , MotionControllerVisualizer visualizerScript )
149+ public void LoadInfo ( Transform [ ] childTransforms )
67150 {
68151 foreach ( Transform child in childTransforms )
69152 {
@@ -75,6 +158,12 @@ public void LoadInfo(Transform[] childTransforms, MotionControllerVisualizer vis
75158 // visualizer.
76159 switch ( child . name . ToLower ( ) )
77160 {
161+ case "touch" :
162+ touchpadTouchVisualizer = MotionControllerVisualizer . Instance . SpawnTouchpadVisualizer ( child ) ;
163+ break ;
164+ case "pointing_pose" :
165+ pointingPose = child . gameObject ;
166+ break ;
78167 case "pressed" :
79168 switch ( child . parent . name . ToLower ( ) )
80169 {
@@ -190,9 +279,6 @@ public void LoadInfo(Transform[] childTransforms, MotionControllerVisualizer vis
190279 break ;
191280 }
192281 break ;
193- case "touch" :
194- touchpadTouchVisualizer = visualizerScript . SpawnTouchpadVisualizer ( child ) ;
195- break ;
196282 }
197283 }
198284 }
@@ -289,5 +375,14 @@ private void SetLocalPositionAndRotation(GameObject buttonGameObject, Transform
289375 buttonGameObject . transform . localPosition = newTransform . localPosition ;
290376 buttonGameObject . transform . localRotation = newTransform . localRotation ;
291377 }
378+
379+ public void SetRenderersVisible ( bool visible )
380+ {
381+ MeshRenderer [ ] renderers = ControllerParent . GetComponentsInChildren < MeshRenderer > ( ) ;
382+ for ( int i = 0 ; i < renderers . Length ; i ++ )
383+ {
384+ renderers [ i ] . enabled = visible ;
385+ }
386+ }
292387 }
293388}
0 commit comments