Skip to content

Commit d21e3dc

Browse files
committed
Continue migration
1 parent 8e28a31 commit d21e3dc

File tree

9 files changed

+74
-71
lines changed

9 files changed

+74
-71
lines changed

org.mixedrealitytoolkit.core/Interactables/StatefulInteractable.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ protected override void OnDestroy()
263263
/// <remarks>
264264
/// Derived classes should override this method to specify custom selection math.
265265
/// The default implementation allows for variable selection from
266-
/// <see cref="IVariableSelectInteractor"/> objects, calculated using
267-
/// <see cref="IVariableSelectInteractor.SelectProgress"/>.
266+
/// <see cref="IXRInteractionStrengthInteractor"/> objects, calculated using
267+
/// <see cref="IXRInteractionStrengthInteractable.GetInteractionStrength(IXRInteractable)"/>.
268268
/// </remarks>
269269
public virtual float GetSelectionProgress()
270270
{
@@ -274,22 +274,30 @@ public virtual float GetSelectionProgress()
274274

275275
foreach (IXRHoverInteractor interactor in interactorsHovering)
276276
{
277-
if (interactor is IXRInteractionStrengthInteractor iInteractionStrengthInteractor)
277+
if (interactor is IXRInteractionStrengthInteractor interactionStrengthInteractor)
278278
{
279-
selectionProgress = Mathf.Max(selectionProgress, iInteractionStrengthInteractor.largestInteractionStrength.Value);
279+
selectionProgress = Mathf.Max(selectionProgress, GetInteractionStrength(interactor));
280280
}
281+
#pragma warning disable CS0618 // Type or member is obsolete
281282
else if (interactor is IVariableSelectInteractor variableSelectInteractor)
282283
{
283284
selectionProgress = Mathf.Max(selectionProgress, variableSelectInteractor.SelectProgress);
284285
}
286+
#pragma warning restore CS0618 // Type or member is obsolete
285287
}
286288

287-
foreach (var interactor in interactorsSelecting)
289+
foreach (IXRSelectInteractor interactor in interactorsSelecting)
288290
{
289-
if (interactor is IVariableSelectInteractor variableSelectInteractor)
291+
if (interactor is IXRInteractionStrengthInteractor interactionStrengthInteractor)
292+
{
293+
selectionProgress = Mathf.Max(selectionProgress, GetInteractionStrength(interactor));
294+
}
295+
#pragma warning disable CS0618 // Type or member is obsolete
296+
else if (interactor is IVariableSelectInteractor variableSelectInteractor)
290297
{
291298
selectionProgress = Mathf.Max(selectionProgress, variableSelectInteractor.SelectProgress);
292299
}
300+
#pragma warning restore CS0618 // Type or member is obsolete
293301
else
294302
{
295303
selectionProgress = 1.0f;
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
// Copyright (c) Mixed Reality Toolkit Contributors
22
// Licensed under the BSD 3-Clause
33

4+
using UnityEngine.XR.Interaction.Toolkit.Interactors;
5+
46
namespace MixedReality.Toolkit
57
{
68
/// <summary>
79
/// An interface that all gaze-pinch-like interactors must implement.
810
/// </summary>
9-
public interface IGazePinchInteractor : IVariableSelectInteractor
10-
{
11-
12-
}
13-
}
11+
public interface IGazePinchInteractor :
12+
IXRInteractionStrengthInteractor,
13+
#pragma warning disable CS0618 // Type or member is obsolete
14+
IVariableSelectInteractor
15+
#pragma warning restore CS0618 // Type or member is obsolete
16+
{ }
17+
}

org.mixedrealitytoolkit.core/Interactors/IVariableSelectInteractor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace MixedReality.Toolkit
1010
/// An interface that all interactors which offer
1111
/// variable selection must implement.
1212
/// </summary>
13-
[Obsolete]
13+
[Obsolete("Use " + nameof(IXRInteractionStrengthInteractor) + " instead.")]
1414
public interface IVariableSelectInteractor : IXRSelectInteractor, IXRHoverInteractor
1515
{
1616
/// <summary>
@@ -21,7 +21,7 @@ public interface IVariableSelectInteractor : IXRSelectInteractor, IXRHoverIntera
2121
/// For gaze-pinch interactors, this is the pinch progress.
2222
/// For motion controllers, this is the analog trigger press amount.
2323
/// </remarks>
24-
[Obsolete]
24+
[Obsolete("Use " + nameof(IXRInteractionStrengthInteractor.GetInteractionStrength) + " or " + nameof(IXRInteractionStrengthInteractor.largestInteractionStrength) + " instead.")]
2525
float SelectProgress { get; }
2626
}
2727
}

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

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -197,43 +197,29 @@ private bool IsTracked
197197

198198
/// <inheritdoc />
199199
[Obsolete("Use " + nameof(handedness) + " instead.")]
200-
Handedness IHandedInteractor.Handedness
201-
{
202-
get
203-
{
204-
if (forceDeprecatedInput)
205-
{
206-
return handController.HandNode.ToHandedness();
207-
}
208-
209-
return handedness.ToHandedness();
210-
}
211-
}
200+
Handedness IHandedInteractor.Handedness => forceDeprecatedInput ? handController.HandNode.ToHandedness() : handedness.ToHandedness();
212201

213202
#endregion IHandedInteractor
214203

215204
#region IVariableSelectInteractor
216205

217206
/// <inheritdoc />
218-
public float SelectProgress
207+
[Obsolete("Use " + nameof(IXRInteractionStrengthInteractor.GetInteractionStrength) + " or " + nameof(IXRInteractionStrengthInteractor.largestInteractionStrength) + " instead.")]
208+
float IVariableSelectInteractor.SelectProgress
219209
{
220210
get
221211
{
222-
#pragma warning disable CS0618 // Type or member is obsolete
223212
if (forceDeprecatedInput)
224213
{
225214
return handController.selectInteractionState.value;
226215
}
227-
#pragma warning restore CS0618 // Type or member is obsolete
228216
else if (selectInput != null)
229217
{
230218
return selectInput.ReadValue();
231219
}
232-
else
233-
{
234-
Debug.LogWarning($"Unable to determine SelectProgress of {name} because there is no Select Input Configuration set for this interactor.");
235-
}
236-
return 0.0f;
220+
221+
Debug.LogWarning($"Unable to determine SelectProgress of {name} because there is no Select Input Configuration set for this interactor.");
222+
return 0;
237223
}
238224
}
239225

@@ -286,7 +272,7 @@ public override void GetValidTargets(List<IXRInteractable> targets)
286272
// If we are hovering something and also have gone past the sticky hover threshold,
287273
// we should *only* consider the current hover target, regardless of what the
288274
// gaze is currently actually looking at. (Sticky hover, ADO#1941)
289-
if (hasHover && SelectProgress > stickyHoverThreshold)
275+
if (hasHover && largestInteractionStrength.Value > stickyHoverThreshold)
290276
{
291277
targets.Add(interactablesHovered[0]);
292278
}
@@ -404,7 +390,7 @@ public override bool CanHover(IXRHoverInteractable interactable)
404390
// If so, should we be allowed to initiate a new hover on it?
405391
// This prevents us from "rolling off" one target and immediately
406392
// semi-pressing another.
407-
bool canHoverNew = !isNew || SelectProgress < relaxationThreshold;
393+
bool canHoverNew = !isNew || largestInteractionStrength.Value < relaxationThreshold;
408394

409395
return base.CanHover(interactable) && stickySelect && ready && canHoverNew;
410396
}

org.mixedrealitytoolkit.input/Interactors/InteractorVisuals/MRTKLineVisual.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,20 +391,19 @@ private void UpdateLineVisual()
391391

392392
// Now handle coloring the line visual
393393
// If our interactor is a variable select interactor, change the material property based on select progress
394-
IVariableSelectInteractor variableSelectInteractor = rayInteractor as IVariableSelectInteractor;
395-
if (variableSelectInteractor != null)
394+
if (rayInteractor != null)
396395
{
397396
lineRenderer.GetPropertyBlock(propertyBlock);
398-
propertyBlock.SetFloat("_Shift_", variableSelectInteractor.SelectProgress);
397+
propertyBlock.SetFloat("_Shift_", rayInteractor.largestInteractionStrength.Value);
399398
lineRenderer.SetPropertyBlock(propertyBlock);
400399
}
401400

402401
// If we are hovering over a valid object or are currently selecting one, lerp the color based on selectedness
403402
if (rayHasHit || rayInteractor.hasSelection)
404403
{
405-
if (variableSelectInteractor != null)
404+
if (rayInteractor != null)
406405
{
407-
cachedGradient = ColorUtilities.GradientLerp(ValidColorGradient, SelectActiveColorGradient, variableSelectInteractor.SelectProgress);
406+
cachedGradient = ColorUtilities.GradientLerp(ValidColorGradient, SelectActiveColorGradient, rayInteractor.largestInteractionStrength.Value);
408407
}
409408
else
410409
{

org.mixedrealitytoolkit.input/Interactors/InteractorVisuals/RingReticle.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,16 @@ public void UpdateVisual(ReticleVisualUpdateArgs args)
100100
{
101101
if (displaySelectionProgress)
102102
{
103-
if (args.Interactor is IVariableSelectInteractor variableSelectInteractor)
103+
if (args.Interactor is IXRInteractionStrengthInteractor interactionStrengthInteractor)
104+
{
105+
UpdateReticleProgressVisual(interactionStrengthInteractor.largestInteractionStrength.Value);
106+
}
107+
#pragma warning disable CS0618 // Type or member is obsolete
108+
else if (args.Interactor is IVariableSelectInteractor variableSelectInteractor)
104109
{
105110
UpdateReticleProgressVisual(variableSelectInteractor.SelectProgress);
106111
}
112+
#pragma warning restore CS0618 // Type or member is obsolete
107113
else if (args.Interactor is IXRSelectInteractor selectInteractor)
108114
{
109115
UpdateReticleProgressVisual(selectInteractor.isSelectActive ? 1 : 0);

org.mixedrealitytoolkit.input/Interactors/Ray/MRTKRayInteractor.cs

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@ namespace MixedReality.Toolkit.Input
2727
public class MRTKRayInteractor :
2828
XRRayInteractor,
2929
IRayInteractor,
30-
IXRSelectInteractor,
31-
IXRHoverInteractor,
3230
IModeManagedInteractor,
3331
#pragma warning disable CS0618 // Type or member is obsolete
34-
IHandedInteractor,
35-
IVariableSelectInteractor
32+
IVariableSelectInteractor,
33+
IHandedInteractor
3634
#pragma warning restore CS0618 // Type or member is obsolete
3735
{
3836
#region MRTKRayInteractor
@@ -144,36 +142,26 @@ private bool IsTracked
144142
#region IHandedInteractor
145143

146144
/// <inheritdoc />
147-
[Obsolete("Use handedness from IXRInteractor instead.")]
148-
Handedness IHandedInteractor.Handedness
149-
{
150-
get
151-
{
152-
if (forceDeprecatedInput &&
153-
xrController is ArticulatedHandController handController)
154-
{
155-
return handController.HandNode.ToHandedness();
156-
}
157-
158-
return handedness.ToHandedness();
159-
}
160-
}
145+
[Obsolete("Use " + nameof(handedness) + " instead.")]
146+
Handedness IHandedInteractor.Handedness => forceDeprecatedInput &&
147+
xrController is ArticulatedHandController handController
148+
? handController.HandNode.ToHandedness()
149+
: handedness.ToHandedness();
161150

162151
#endregion IHandedInteractor
163152

164153
#region IVariableSelectInteractor
165154

166155
/// <inheritdoc />
167-
public float SelectProgress
156+
[Obsolete("Use " + nameof(IXRInteractionStrengthInteractor.GetInteractionStrength) + " or " + nameof(IXRInteractionStrengthInteractor.largestInteractionStrength) + " instead.")]
157+
float IVariableSelectInteractor.SelectProgress
168158
{
169159
get
170160
{
171-
#pragma warning disable CS0618 // Type or member is obsolete
172161
if (forceDeprecatedInput)
173162
{
174163
return xrController.selectInteractionState.value;
175164
}
176-
#pragma warning restore CS0618
177165
else if (selectInput != null)
178166
{
179167
return selectInput.ReadValue();
@@ -208,7 +196,7 @@ public override bool CanHover(IXRHoverInteractable interactable)
208196
// If so, should we be allowed to initiate a new hover on it?
209197
// This prevents us from "rolling off" one target and immediately
210198
// semi-pressing another.
211-
bool canHoverNew = !isNew || SelectProgress < relaxationThreshold;
199+
bool canHoverNew = !isNew || largestInteractionStrength.Value < relaxationThreshold;
212200

213201
return ready && base.CanHover(interactable) && canHoverNew;
214202
}
@@ -309,7 +297,7 @@ public override void ProcessInteractor(XRInteractionUpdateOrder.UpdatePhase upda
309297
if (updatePhase == XRInteractionUpdateOrder.UpdatePhase.Dynamic)
310298
{
311299
// If we've fully relaxed, we can begin hovering/selecting a new target.
312-
if (SelectProgress < relaxationThreshold)
300+
if (largestInteractionStrength.Value < relaxationThreshold)
313301
{
314302
isRelaxedBeforeSelect = true;
315303
}

org.mixedrealitytoolkit.uxcomponents.noncanvas/Tests/Runtime/PressableButtonTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ public IEnumerator ButtonInstantiateDisableThenEnableBeforeStart([ValueSource(na
7777

7878
PressableButton buttonComponent = testButton.GetComponent<PressableButton>();
7979

80-
// We don't get inheritdoc summaries here for some reason?
8180
var selectedness = buttonComponent.GetSelectionProgress();
8281

8382
Assert.IsTrue(selectedness == 0.0f, "The button prefabs should start with 0 selectedness");

org.mixedrealitytoolkit.uxcore/Button/PressableButton.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public SpaceMode DistanceSpaceMode
200200
/// <summary>
201201
/// If the <see cref="GetSelectionProgress"/> value is smoothed to within this threshold of 0 or 1, the <see cref="GetSelectionProgress"/> will snap to 0 or 1.
202202
/// </summary>
203-
private const float selectionProgressEpsilon = 0.00001f;
203+
private const float SelectionProgressEpsilon = 0.00001f;
204204

205205
#endregion Private Members
206206

@@ -416,20 +416,34 @@ public override void ProcessInteractable(XRInteractionUpdateOrder.UpdatePhase up
416416

417417
foreach (var interactor in interactorsHovering)
418418
{
419-
if (interactor is IVariableSelectInteractor variableSelectInteractor)
419+
if (interactor is IXRInteractionStrengthInteractor interactionStrengthInteractor)
420+
{
421+
totalPressProgress = Mathf.Max(totalPressProgress, GetInteractionStrength(interactor));
422+
isVariablySelected = true;
423+
}
424+
#pragma warning disable CS0618 // Type or member is obsolete
425+
else if (interactor is IVariableSelectInteractor variableSelectInteractor)
420426
{
421427
totalPressProgress = Mathf.Max(totalPressProgress, variableSelectInteractor.SelectProgress);
422428
isVariablySelected = true;
423429
}
430+
#pragma warning restore CS0618 // Type or member is obsolete
424431
}
425432

426433
foreach (var interactor in interactorsSelecting)
427434
{
428-
if (interactor is IVariableSelectInteractor variableSelectInteractor)
435+
if (interactor is IXRInteractionStrengthInteractor interactionStrengthInteractor)
436+
{
437+
totalPressProgress = Mathf.Max(totalPressProgress, GetInteractionStrength(interactor));
438+
isVariablySelected = true;
439+
}
440+
#pragma warning disable CS0618 // Type or member is obsolete
441+
else if (interactor is IVariableSelectInteractor variableSelectInteractor)
429442
{
430443
totalPressProgress = Mathf.Max(totalPressProgress, variableSelectInteractor.SelectProgress);
431444
isVariablySelected = true;
432445
}
446+
#pragma warning restore CS0618 // Type or member is obsolete
433447
else if (!(interactor is IPokeInteractor)) // Exclude PokeInteractors because we've already counted them.
434448
{
435449
totalPressProgress = 1.0f;
@@ -445,12 +459,11 @@ public override void ProcessInteractable(XRInteractionUpdateOrder.UpdatePhase up
445459
selectionProgress = Mathf.Lerp(selectionProgress, totalPressProgress, totalPressProgress == 1 ? extendSpeed : returnSpeed);
446460

447461
// Snap selectionProgress to ends of range, plus/minus selectionProgressEpsilon.
448-
if (selectionProgress < selectionProgressEpsilon)
462+
if (selectionProgress < SelectionProgressEpsilon)
449463
{
450464
selectionProgress = 0;
451465
}
452-
453-
if (selectionProgress > 1 - selectionProgressEpsilon)
466+
else if (selectionProgress > 1 - SelectionProgressEpsilon)
454467
{
455468
selectionProgress = 1;
456469
}

0 commit comments

Comments
 (0)