@@ -27,7 +27,7 @@ public class SolverHandler : MonoBehaviour
2727 /// </summary>
2828 public TrackedObjectType TrackedTargetType
2929 {
30- get { return trackedTargetType ; }
30+ get => trackedTargetType ;
3131 set
3232 {
3333 if ( trackedTargetType != value && IsValidTrackedObjectType ( value ) )
@@ -38,23 +38,6 @@ public TrackedObjectType TrackedTargetType
3838 }
3939 }
4040
41- /// <summary>
42- /// Tracked object to calculate position and orientation from. If you want to manually override and use a scene object, use the TransformTarget field.
43- /// </summary>
44- [ Obsolete ( "Use TrackedTargetType instead" ) ]
45- public TrackedObjectType TrackedObjectToReference
46- {
47- get { return trackedTargetType ; }
48- set
49- {
50- if ( trackedTargetType != value )
51- {
52- trackedTargetType = value ;
53- RefreshTrackedObject ( ) ;
54- }
55- }
56- }
57-
5841 [ SerializeField ]
5942 [ Tooltip ( "If tracking hands or motion controllers, determines which hand(s) are valid attachments" ) ]
6043 private Handedness trackedHandness = Handedness . Both ;
@@ -67,7 +50,7 @@ public TrackedObjectType TrackedObjectToReference
6750 /// </remarks>
6851 public Handedness TrackedHandness
6952 {
70- get { return trackedHandness ; }
53+ get => trackedHandness ;
7154 set
7255 {
7356 if ( trackedHandness != value && IsValidHandedness ( value ) )
@@ -87,7 +70,7 @@ public Handedness TrackedHandness
8770 /// </summary>
8871 public TrackedHandJoint TrackedHandJoint
8972 {
90- get { return trackedHandJoint ; }
73+ get => trackedHandJoint ;
9174 set
9275 {
9376 if ( trackedHandJoint != value )
@@ -126,7 +109,7 @@ public Transform TransformOverride
126109 /// </summary>
127110 public Vector3 AdditionalOffset
128111 {
129- get { return additionalOffset ; }
112+ get => additionalOffset ;
130113 set
131114 {
132115 if ( additionalOffset != value )
@@ -146,7 +129,7 @@ public Vector3 AdditionalOffset
146129 /// </summary>
147130 public Vector3 AdditionalRotation
148131 {
149- get { return additionalRotation ; }
132+ get => additionalRotation ;
150133 set
151134 {
152135 if ( additionalRotation != value )
@@ -166,8 +149,8 @@ public Vector3 AdditionalRotation
166149 /// </summary>
167150 public bool UpdateSolvers
168151 {
169- get { return updateSolvers ; }
170- set { updateSolvers = value ; }
152+ get => updateSolvers ;
153+ set => updateSolvers = value ;
171154 }
172155
173156 protected readonly List < Solver > solvers = new List < Solver > ( ) ;
@@ -178,17 +161,13 @@ public bool UpdateSolvers
178161 /// </summary>
179162 public IReadOnlyCollection < Solver > Solvers
180163 {
181- get
182- {
183- return solvers . AsReadOnly ( ) ;
184- }
185-
164+ get => solvers . AsReadOnly ( ) ;
186165 set
187166 {
188167 if ( value != null )
189168 {
190- this . solvers . Clear ( ) ;
191- this . solvers . AddRange ( value ) ;
169+ solvers . Clear ( ) ;
170+ solvers . AddRange ( value ) ;
192171 }
193172 }
194173 }
@@ -230,7 +209,7 @@ public Transform TransformTarget
230209 RefreshTrackedObject ( ) ;
231210 }
232211
233- return ( trackingTarget != null ) ? trackingTarget . transform : null ;
212+ return trackingTarget != null ? trackingTarget . transform : null ;
234213 }
235214 }
236215
@@ -243,13 +222,7 @@ public Transform TransformTarget
243222 /// /// <remarks>
244223 /// Only possible values Left, Right, or None
245224 /// </remarks>
246- public Handedness CurrentTrackedHandedness
247- {
248- get
249- {
250- return currentTrackedHandedness ;
251- }
252- }
225+ public Handedness CurrentTrackedHandedness => currentTrackedHandedness ;
253226
254227 // Stores controller side to favor if TrackedHandedness is set to both
255228 protected Handedness preferredTrackedHandedness = Handedness . Left ;
@@ -277,6 +250,8 @@ public Handedness PreferredTrackedHandedness
277250 // Hidden GameObject managed by this component and attached as a child to the tracked target type (i.e head, hand etc)
278251 private GameObject trackingTarget ;
279252
253+ private LinePointer controllerRay ;
254+
280255 private float lastUpdateTime ;
281256
282257 private IMixedRealityHandJointService HandJointService => handJointService ?? ( handJointService = ( CoreServices . InputSystem as IMixedRealityDataProviderAccess ) ? . GetDataProvider < IMixedRealityHandJointService > ( ) ) ;
@@ -397,6 +372,7 @@ protected virtual void DetachFromCurrentTrackedObject()
397372 protected virtual void AttachToNewTrackedObject ( )
398373 {
399374 currentTrackedHandedness = Handedness . None ;
375+ controllerRay = null ;
400376
401377 Transform target = null ;
402378 if ( TrackedTargetType == TrackedObjectType . Head )
@@ -408,21 +384,28 @@ protected virtual void AttachToNewTrackedObject()
408384 if ( TrackedHandness == Handedness . Both )
409385 {
410386 currentTrackedHandedness = PreferredTrackedHandedness ;
411- target = GetControllerRay ( currentTrackedHandedness ) ;
412- if ( target == null )
387+ controllerRay = PointerUtils . GetPointer < LinePointer > ( currentTrackedHandedness ) ;
388+
389+ if ( controllerRay == null )
413390 {
391+ // If no pointer found, try again on the the opposite hand
414392 currentTrackedHandedness = currentTrackedHandedness . GetOppositeHandedness ( ) ;
415- target = GetControllerRay ( currentTrackedHandedness ) ;
416- if ( target == null )
417- {
418- currentTrackedHandedness = Handedness . None ;
419- }
393+ controllerRay = PointerUtils . GetPointer < LinePointer > ( currentTrackedHandedness ) ;
420394 }
421395 }
422396 else
423397 {
424398 currentTrackedHandedness = TrackedHandness ;
425- target = GetControllerRay ( TrackedHandness ) ;
399+ controllerRay = PointerUtils . GetPointer < LinePointer > ( currentTrackedHandedness ) ;
400+ }
401+
402+ if ( controllerRay != null )
403+ {
404+ target = controllerRay . transform ;
405+ }
406+ else
407+ {
408+ currentTrackedHandedness = Handedness . None ;
426409 }
427410 }
428411 else if ( TrackedTargetType == TrackedObjectType . HandJoint )
@@ -470,10 +453,9 @@ private void TrackTransform(Transform target)
470453 trackingTarget . transform . localRotation = Quaternion . Euler ( AdditionalRotation ) ;
471454 }
472455
473- private Transform GetControllerRay ( Handedness handedness )
456+ private LinePointer GetControllerRay ( Handedness handedness )
474457 {
475- var pointer = PointerUtils . GetPointer < LinePointer > ( handedness ) ;
476- return pointer ? . transform ;
458+ return PointerUtils . GetPointer < LinePointer > ( handedness ) ;
477459 }
478460
479461 /// <summary>
@@ -486,7 +468,15 @@ private bool IsInvalidTracking()
486468 {
487469 return true ;
488470 }
489-
471+
472+ // If we are attached to a pointer (i.e controller ray),
473+ // check if pointer's controller is still be tracked
474+ if ( TrackedTargetType == TrackedObjectType . ControllerRay &&
475+ ( controllerRay == null || ! controllerRay . IsTracked ) )
476+ {
477+ return true ;
478+ }
479+
490480 // If we were tracking a particular hand, check that our transform is still valid
491481 // The HandJointService does not destroy it's own hand joint tracked GameObjects even when a hand is no longer tracked
492482 // Those HandJointService's GameObjects though are the parents of our tracked transform and thus will not be null/destroyed
@@ -511,5 +501,26 @@ public static bool IsValidTrackedObjectType(TrackedObjectType type)
511501 {
512502 return type == TrackedObjectType . Head || type >= TrackedObjectType . ControllerRay ;
513503 }
504+
505+ #region Obsolete
506+
507+ /// <summary>
508+ /// Tracked object to calculate position and orientation from. If you want to manually override and use a scene object, use the TransformTarget field.
509+ /// </summary>
510+ [ Obsolete ( "Use TrackedTargetType instead" ) ]
511+ public TrackedObjectType TrackedObjectToReference
512+ {
513+ get => trackedTargetType ;
514+ set
515+ {
516+ if ( trackedTargetType != value )
517+ {
518+ trackedTargetType = value ;
519+ RefreshTrackedObject ( ) ;
520+ }
521+ }
522+ }
523+
524+ #endregion
514525 }
515526}
0 commit comments