@@ -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
0 commit comments