Skip to content

Commit e69be7f

Browse files
committed
Adding ability to change handedness in ControllerFinder, instead of destroying/instantiating
1 parent 8058e72 commit e69be7f

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

Assets/HoloToolkit/Input/Scripts/Focus/SimpleSinglePointerSelector.cs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public class SimpleSinglePointerSelector : MonoBehaviour, ISourceStateHandler, I
3939
[SerializeField]
4040
private GameObject linePointerPrefab;
4141

42+
private PointerLine instantiatedPointerLine;
43+
4244
#endregion
4345

4446
#region Data
@@ -301,30 +303,39 @@ private void AttachInputSourcePointer(IInputSource inputSource, uint sourceId)
301303
inputSourcePointer.ExtentOverride = null;
302304
inputSourcePointer.PrioritizedLayerMasksOverride = null;
303305

304-
if (inputSourcePointer.PointerRay != null)
306+
InteractionInputSource interactionInputSource = inputSource as InteractionInputSource;
307+
308+
if (interactionInputSource == null)
305309
{
306-
Destroy(inputSourcePointer.PointerRay.gameObject);
310+
return;
307311
}
308312

309-
if (inputSource is InteractionInputSource && linePointerPrefab != null)
313+
if (linePointerPrefab == null)
314+
{
315+
return;
316+
}
317+
318+
if (instantiatedPointerLine == null)
319+
{
320+
instantiatedPointerLine = Instantiate(linePointerPrefab).GetComponent<PointerLine>();
321+
}
322+
323+
inputSourcePointer.PointerRay = instantiatedPointerLine;
324+
325+
Handedness handedness;
326+
if (interactionInputSource.TryGetHandedness(sourceId, out handedness))
310327
{
311-
inputSourcePointer.PointerRay = Instantiate(linePointerPrefab).GetComponent<PointerLine>();
312-
inputSourcePointer.PointerRay.ExtentOverride = Cursor.DefaultCursorDistance;
313-
Handedness handedness;
314-
if (((InteractionInputSource)inputSource).TryGetHandedness(sourceId, out handedness))
315-
{
316328
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
317-
inputSourcePointer.PointerRay.Handedness = (InteractionSourceHandedness)handedness;
329+
instantiatedPointerLine.ChangeHandedness((InteractionSourceHandedness)handedness);
318330
#endif
319-
}
320331
}
321332
}
322333

323334
private void DetachInputSourcePointer()
324335
{
325-
if (inputSourcePointer.PointerRay != null)
336+
if (instantiatedPointerLine != null)
326337
{
327-
Destroy(inputSourcePointer.PointerRay.gameObject);
338+
Destroy(instantiatedPointerLine.gameObject);
328339
}
329340
}
330341

Assets/HoloToolkit/Input/Scripts/Utilities/ControllerFinder.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ protected virtual void OnDestroy()
9090
#endif
9191
}
9292

93+
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
94+
public void ChangeHandedness(InteractionSourceHandedness newHandedness)
95+
{
96+
if (newHandedness != handedness)
97+
{
98+
RemoveControllerTransform(ControllerInfo);
99+
handedness = newHandedness;
100+
CheckModelAlreadyLoaded();
101+
}
102+
}
103+
#endif
104+
93105
protected virtual void AddControllerTransform(MotionControllerInfo newController)
94106
{
95107
#if UNITY_WSA && UNITY_2017_2_OR_NEWER

0 commit comments

Comments
 (0)