Skip to content

Commit 4cfd33c

Browse files
authored
Deprecate IHandedInteractor (#1042)
* Style update * Update InteractablePulse.cs * Add migration path for handedness * Actually, this is assigned at runtime, so not usable at serialization time * Update interface lists * Improve fallback logic * Update changelogs and package preview versions * Update GazePinchInteractor.cs
1 parent 3004c9e commit 4cfd33c

File tree

18 files changed

+139
-169
lines changed

18 files changed

+139
-169
lines changed

org.mixedrealitytoolkit.core/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
77
### Added
88

99
* Added input action focus handling to disable controller/hand tracked state when the application goes out of focus. [PR #1039](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/1039)
10+
* Added ToInteractorHandedness extension for XRNode. [PR #1042](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/1042)
1011

1112
### Changed
1213

@@ -17,6 +18,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
1718

1819
* Removed ITrackedInteractor, as it was supporting an unused codepath and there are better ways to get this data (like querying the attach transform). [PR #1044](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/1044)
1920

21+
### Deprecated
22+
23+
* Deprecated IHandedInteractor, as its info is now queryable directly from IXRInteractor's handedness property. [PR #1042](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/1042)
24+
2025
## [4.0.0-development.pre.1] - 2024-07-09
2126

2227
### Added
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
// Copyright (c) Mixed Reality Toolkit Contributors
22
// Licensed under the BSD 3-Clause
33

4+
using System;
45
using UnityEngine.XR.Interaction.Toolkit.Interactors;
56

67
namespace MixedReality.Toolkit
78
{
89
/// <summary>
910
/// An interface that all interactors with the concept of handedness implement.
1011
/// </summary>
12+
[Obsolete("Use handedness from IXRInteractor instead.")]
1113
public interface IHandedInteractor : IXRInteractor
1214
{
1315
/// <summary>
1416
/// Returns the Handedness of this interactor.
1517
/// </summary>
18+
[Obsolete("Use handedness from IXRInteractor instead.")]
1619
public Handedness Handedness { get; }
1720
}
1821
}

org.mixedrealitytoolkit.core/Utilities/Extensions/HandednessExtensions.cs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,12 @@ public static class HandednessExtensions
1717
/// If Left, returns Right, if Right, returns Left otherwise returns None.
1818
/// Otherwise, returns None
1919
/// </remarks>
20-
public static Handedness GetOppositeHandedness(this Handedness current)
20+
public static Handedness GetOppositeHandedness(this Handedness current) => current switch
2121
{
22-
if (current == Handedness.Left)
23-
{
24-
return Handedness.Right;
25-
}
26-
else if (current == Handedness.Right)
27-
{
28-
return Handedness.Left;
29-
}
30-
else
31-
{
32-
return Handedness.None;
33-
}
34-
}
22+
Handedness.Left => Handedness.Right,
23+
Handedness.Right => Handedness.Left,
24+
_ => Handedness.None
25+
};
3526

3627
/// <summary>
3728
/// Checks whether or not the current <see cref="Handedness"/> value matches the specified value.
@@ -53,11 +44,11 @@ public static bool IsMatch(this Handedness current, Handedness compare)
5344
/// <returns>
5445
/// <see cref="XRNode"/> representing the specified <see cref="Handedness"/>, or <see langword="null"/>.
5546
/// </returns>
56-
public static XRNode? ToXRNode(this Handedness hand)
47+
public static XRNode? ToXRNode(this Handedness hand) => hand switch
5748
{
58-
if (hand == Handedness.Left) { return XRNode.LeftHand; }
59-
if (hand == Handedness.Right) { return XRNode.RightHand; }
60-
return null;
61-
}
49+
Handedness.Left => XRNode.LeftHand,
50+
Handedness.Right => XRNode.RightHand,
51+
_ => null
52+
};
6253
}
6354
}

org.mixedrealitytoolkit.core/Utilities/Extensions/InteractorHandednessExtensions.cs

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,12 @@ public static class InteractorHandednessExtensions
2626
/// <summary>
2727
/// Gets the <see cref="XRNode"/> representing the specified <see cref="InteractorHandedness"/>. If the <see cref="InteractorHandedness"/>
2828
/// </summary>
29-
public static XRNode ToXRNode(this InteractorHandedness hand, XRNode defaultValue = XRNode.RightHand)
29+
public static XRNode ToXRNode(this InteractorHandedness hand, XRNode defaultValue = XRNode.RightHand) => hand switch
3030
{
31-
switch (hand)
32-
{
33-
case InteractorHandedness.Left:
34-
return XRNode.LeftHand;
35-
case InteractorHandedness.Right:
36-
return XRNode.RightHand;
37-
default:
38-
return defaultValue;
39-
}
40-
}
31+
InteractorHandedness.Left => XRNode.LeftHand,
32+
InteractorHandedness.Right => XRNode.RightHand,
33+
_ => defaultValue,
34+
};
4135

4236
/// <summary>
4337
/// Converts the <see cref="InteractorHandedness"/> to <see cref="Handedness"/>. If the <see cref="InteractorHandedness"/>
@@ -46,17 +40,11 @@ public static XRNode ToXRNode(this InteractorHandedness hand, XRNode defaultValu
4640
/// <param name="hand">The <see cref="InteractorHandedness"/> value for
4741
/// which the <see cref="Handedness"/> is requested.</param>
4842
/// <returns><see cref="Handedness"/> representing the specified <see cref="InteractorHandedness"/>.</returns>
49-
public static Handedness ToHandedness(this InteractorHandedness hand)
43+
public static Handedness ToHandedness(this InteractorHandedness hand) => hand switch
5044
{
51-
switch (hand)
52-
{
53-
case InteractorHandedness.Left:
54-
return Handedness.Left;
55-
case InteractorHandedness.Right:
56-
return Handedness.Right;
57-
default:
58-
return Handedness.None;
59-
}
60-
}
45+
InteractorHandedness.Left => Handedness.Left,
46+
InteractorHandedness.Right => Handedness.Right,
47+
_ => Handedness.None,
48+
};
6149
}
6250
}

org.mixedrealitytoolkit.core/Utilities/Extensions/XRNodeExtensions.cs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the BSD 3-Clause
33

44
using UnityEngine.XR;
5+
using UnityEngine.XR.Interaction.Toolkit.Interactors;
56

67
namespace MixedReality.Toolkit
78
{
@@ -21,20 +22,30 @@ public static class XRNodeExtensions
2122
/// This will return <see cref="Handedness.None"/> for XRNode values other than
2223
/// LeftHand or RightHand.
2324
/// </remarks>
24-
public static Handedness ToHandedness(this XRNode node)
25+
public static Handedness ToHandedness(this XRNode node) => node switch
2526
{
26-
switch (node)
27-
{
28-
case XRNode.LeftHand:
29-
return Handedness.Left;
27+
XRNode.LeftHand => Handedness.Left,
28+
XRNode.RightHand => Handedness.Right,
29+
_ => Handedness.None,
30+
};
3031

31-
case XRNode.RightHand:
32-
return Handedness.Right;
33-
34-
default:
35-
return Handedness.None;
36-
}
37-
}
32+
/// <summary>
33+
/// Returns the <see cref="InteractorHandedness"/> of the specified XRNode.
34+
/// </summary>
35+
/// <param name="node">The XRNode for which the <see cref="InteractorHandedness"/> is requested.</param>
36+
/// <returns>
37+
/// <see cref="InteractorHandedness"/> value representing the XRNode.
38+
/// </returns>
39+
/// <remarks>
40+
/// This will return <see cref="InteractorHandedness.None"/> for XRNode values other than
41+
/// LeftHand or RightHand.
42+
/// </remarks>
43+
public static InteractorHandedness ToInteractorHandedness(this XRNode node) => node switch
44+
{
45+
XRNode.LeftHand => InteractorHandedness.Left,
46+
XRNode.RightHand => InteractorHandedness.Right,
47+
_ => InteractorHandedness.None,
48+
};
3849

3950
/// <summary>
4051
/// Determine if the specified XRNode represents a hand.
@@ -72,4 +83,4 @@ public static bool IsRightHand(this XRNode node)
7283
return (node == XRNode.RightHand);
7384
}
7485
}
75-
}
86+
}

org.mixedrealitytoolkit.input/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
1818

1919
* Updated the minimum editor version to 2022.3.6f1 [PR #1003](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/1003)
2020

21+
### Deprecated
22+
23+
* Deprecated IHandedInteractor across the interactor implementations, as its info is now queryable directly from IXRInteractor's handedness property. [PR #1042](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/1042)
24+
2125
## [4.0.0-development.pre.1] - 2024-07-16
2226

2327
### Added

org.mixedrealitytoolkit.input/Controllers/ArticulatedHandController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace MixedReality.Toolkit.Input
1717
/// This is able to support variable pinch select through the use of <see cref="HandsAggregatorSubsystem"/>.
1818
/// </remarks>
1919
[AddComponentMenu("MRTK/Input/XR Controller (Articulated Hand)")]
20-
[Obsolete]
20+
[Obsolete("ArticulatedHandController has been deprecated in version 4.0.0. Its functionality has been distributed into different components.")]
2121
public class ArticulatedHandController : ActionBasedController
2222
{
2323
#region Associated hand select values

org.mixedrealitytoolkit.input/InteractionModes/InteractionModeManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ private GameObject FindInteractorGroupObject(XRBaseInteractor interactor)
561561
GameObject interactorGroupObject = null;
562562

563563
// For backwards compatibility, we will continue to support the obsolete "controller-based" interactors,
564-
// and group based on "controller" partents.
564+
// and group based on "controller" parents.
565565
#pragma warning disable CS0618 // xrController is obsolete
566566
if (interactor is XRBaseInputInteractor controllerInteractor &&
567567
controllerInteractor.xrController != null)

org.mixedrealitytoolkit.input/Interactors/Gaze/GazeInteractor.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,7 @@ public GameObject GetModeManagedController()
3939
{
4040
// Legacy controller-based interactors should return null, so the legacy controller-based logic in the
4141
// interaction mode manager is used instead.
42-
#pragma warning disable CS0618 // forceDeprecatedInput is obsolete
43-
if (forceDeprecatedInput)
44-
{
45-
return null;
46-
}
47-
#pragma warning restore CS0618 // forceDeprecatedInput is obsolete
48-
49-
return ModeManagedRoot;
42+
return forceDeprecatedInput ? null : ModeManagedRoot;
5043
}
5144
}
5245
}

org.mixedrealitytoolkit.input/Interactors/GazePinch/GazePinchInteractor.cs

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ namespace MixedReality.Toolkit.Input
2121
public class GazePinchInteractor :
2222
XRBaseInputInteractor,
2323
IGazePinchInteractor,
24-
IHandedInteractor,
25-
IModeManagedInteractor
24+
IModeManagedInteractor,
25+
#pragma warning disable CS0618 // Type or member is obsolete
26+
IHandedInteractor
27+
#pragma warning restore CS0618 // Type or member is obsolete
2628
{
2729
#region GazePinchInteractor
2830

@@ -68,7 +70,7 @@ public GameObject ModeManagedRoot
6870
/// represents whether the hand is in a pinching pose,
6971
/// within the FOV set by the aggregator config.
7072
/// </summary>
71-
protected bool PinchReady { get => pinchReady; }
73+
protected bool PinchReady => pinchReady;
7274

7375
/// <summary>
7476
/// The world-space pose of the hand pinching point.
@@ -194,22 +196,17 @@ private bool IsTracked
194196
#region IHandedInteractor
195197

196198
/// <inheritdoc />
199+
[Obsolete("Use handedness from IXRInteractor instead.")]
197200
Handedness IHandedInteractor.Handedness
198201
{
199202
get
200203
{
201-
#pragma warning disable CS0618 // Type or member is obsolete
202204
if (forceDeprecatedInput)
203205
{
204-
#pragma warning disable CS0612 // Type or member is obsolete
205206
return handController.HandNode.ToHandedness();
206-
#pragma warning restore CS0612 // Type or member is obsolete
207-
}
208-
#pragma warning restore CS0618 // Type or member is obsolete
209-
else
210-
{
211-
return handedness.ToHandedness();
212207
}
208+
209+
return handedness.ToHandedness();
213210
}
214211
}
215212

@@ -225,9 +222,7 @@ public float SelectProgress
225222
#pragma warning disable CS0618 // Type or member is obsolete
226223
if (forceDeprecatedInput)
227224
{
228-
#pragma warning disable CS0612 // Type or member is obsolete
229225
return handController.selectInteractionState.value;
230-
#pragma warning restore CS0612 // Type or member is obsolete
231226
}
232227
#pragma warning restore CS0618 // Type or member is obsolete
233228
else if (selectInput != null)
@@ -326,11 +321,11 @@ public override void ProcessInteractor(XRInteractionUpdateOrder.UpdatePhase upda
326321

327322
/// <summary>
328323
/// Given the specified interactable, this computes and applies the relevant
329-
/// position and rotation to the attach transform.
324+
/// position and rotation to the attach transform.
330325
/// </summary>
331326
/// <remarks>
332-
/// If there is currently an active selection, the attach transform is computed
333-
/// as an offset from selected object, where the offset vector is a function of
327+
/// If there is currently an active selection, the attach transform is computed
328+
/// as an offset from selected object, where the offset vector is a function of
334329
/// the centroid between all currently participating <see cref="GazePinchInteractor"/>
335330
/// objects. This models ray-like manipulations, but with virtual attach offsets
336331
/// from object, modeled from the relationship between each participating hand.
@@ -344,8 +339,7 @@ private void ComputeAttachTransform(IXRSelectInteractable interactable)
344339
if (!AimPoseSource.TryGetPose(out Pose aimPose)) { return; }
345340

346341
// Separate vars for fused position/rotation setting.
347-
Quaternion rotationToApply = attachTransform.rotation;
348-
Vector3 positionToApply = attachTransform.position;
342+
attachTransform.GetPositionAndRotation(out Vector3 positionToApply, out Quaternion rotationToApply);
349343

350344
// Compute the ratio from the current hand-body distance to the distance
351345
// we recorded on selection. Used to linearly scale the attach transform's
@@ -484,7 +478,7 @@ private void ResetManipulationLogic(IXRSelectInteractable interactable)
484478
interactorLocalAttachPoint = Quaternion.Inverse(noRollRay) * (virtualAttachTransform - aimPose.position);
485479

486480
// Record the distance from the controller to the body of the user, to use as reference for subsequent
487-
// distance measurements.
481+
// distance measurements.
488482
bodyDistanceOnSelect = PoseUtilities.GetDistanceToBody(aimPose);
489483
}
490484

@@ -562,24 +556,20 @@ protected override void OnSelectExited(SelectExitEventArgs args)
562556
#endregion XRBaseInteractor
563557

564558
#region IModeManagedInteractor
559+
565560
/// <inheritdoc/>
566561
[Obsolete("This function is obsolete and will be removed in the next major release. Use ModeManagedRoot instead.")]
567562
public GameObject GetModeManagedController()
568563
{
569564
// Legacy controller-based interactors should return null, so the legacy controller-based logic in the
570565
// interaction mode manager is used instead.
571-
#pragma warning disable CS0618 // Type or member is obsolete
572-
if (forceDeprecatedInput)
573-
{
574-
return null;
575-
}
576-
#pragma warning restore CS0618 // Type or member is obsolete
577-
578-
return ModeManagedRoot;
566+
return forceDeprecatedInput ? null : ModeManagedRoot;
579567
}
568+
580569
#endregion IModeManagedInteractor
581570

582571
#region Private Methods
572+
583573
/// <summary>
584574
/// Updates the pinch state of the GazePinchInteractor.
585575
/// If handedness is not set then it defaults to right hand.
@@ -613,6 +603,7 @@ private void UpdatePinchState()
613603
pinchReady = isPinchReady;
614604
}
615605
}
606+
616607
#endregion Private Methods
617608
}
618609
}

0 commit comments

Comments
 (0)