Skip to content

Commit 82be9f2

Browse files
author
Unity Technologies
committed
com.unity.xr.interaction.toolkit@2.0.3
## [2.0.3] - 2022-07-26 ### Fixed - Fixed the simulated HMD and controllers so they no longer reset to origin after switching focus away and back to the Unity Editor. ([1409417](https://issuetracker.unity3d.com/product/unity/issues/guid/1409417)) - Fixed warnings about setting velocities of a kinematic body when updating an XR Grab Interactable with Movement Type set to Kinematic. - Fixed `UIInputModule` so it will use the new Main Camera if the previous one is disabled when `UIInputModule.uiCamera` is not set. - Fixed warning in the Inspector window for interactors missing the XR Controller component when the GameObject is deactivated by changing the find method to include inactive GameObjects. - Fixed XR Interactor Line Visual so it will instantiate the Reticle GameObject when it is a Prefab asset so it does not modify the asset on disk. - Fixed `UIInputModule` to support EventSystem `IPointerMoveHandler` for Unity 2021.1 and newer. Also added the corresponding `pointerMove` event to `UIInputModule` to allow the pointer move events to be globally handled.
1 parent 3fa7766 commit 82be9f2

19 files changed

+589
-64
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77
<!-- Headers should be listed in this order: Added, Changed, Deprecated, Removed, Fixed, Security -->
8+
## [2.0.3] - 2022-07-26
9+
10+
### Fixed
11+
- Fixed the simulated HMD and controllers so they no longer reset to origin after switching focus away and back to the Unity Editor. ([1409417](https://issuetracker.unity3d.com/product/unity/issues/guid/1409417))
12+
- Fixed warnings about setting velocities of a kinematic body when updating an XR Grab Interactable with Movement Type set to Kinematic.
13+
- Fixed `UIInputModule` so it will use the new Main Camera if the previous one is disabled when `UIInputModule.uiCamera` is not set.
14+
- Fixed warning in the Inspector window for interactors missing the XR Controller component when the GameObject is deactivated by changing the find method to include inactive GameObjects.
15+
- Fixed XR Interactor Line Visual so it will instantiate the Reticle GameObject when it is a Prefab asset so it does not modify the asset on disk.
16+
- Fixed `UIInputModule` to support EventSystem `IPointerMoveHandler` for Unity 2021.1 and newer. Also added the corresponding `pointerMove` event to `UIInputModule` to allow the pointer move events to be globally handled.
17+
818
## [2.0.2] - 2022-04-29
919

1020
### Fixed

Documentation~/installation.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,22 @@ To install this package, refer to the instructions that match your Unity Editor
44

55
## Version 2022.1 and later
66

7-
To install this package, follow the [installation instructions in the Unity User Manual](https://docs.unity3d.com/Documentation/Manual/upm-ui-install.html).
7+
To install this package, follow the [installation instructions in the Unity User Manual](https://docs.unity3d.com/2022.1/Documentation/Manual/upm-ui-install.html).
88

99
## Version 2021.3
1010

11+
### 2021.3.8f1 and later
12+
13+
To install this package, follow the [installation instructions in the Unity User Manual](https://docs.unity3d.com/2021.3/Documentation/Manual/upm-ui-install.html).
14+
15+
### 2021.3.7f1 and earlier
16+
1117
To install this package, follow the instructions for [adding a package by name](https://docs.unity3d.com/2021.3/Documentation/Manual/upm-ui-quick.html) in the Unity Editor.
1218

1319
|Text Field|Value|
1420
|---|---|
1521
|**Name**|`com.unity.xr.interaction.toolkit`|
16-
|**Version (optional)**|`2.0.2`|
22+
|**Version (optional)**|`2.0.3`|
1723

1824
## Version 2020.3
1925

Documentation~/xr-grab-interactable.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Interactable component that hooks into the interaction system (via [XRInteractio
3030
| **Tighten Rotation** | Reduces the maximum follow rotation difference when using smoothing.<br />Fractional amount of how close the smoothed rotation should remain to the rotation of the Interactor when using smoothing. The value ranges from 0 meaning no bias in the smoothed follow rotation, to 1 meaning effectively no smoothing at all. |
3131
| **Angular Velocity Damping** | Scale factor of how much Unity dampens the existing angular velocity when tracking the rotation of the Interactor. The smaller the value, the longer it takes for the angular velocity to decay.<br />Only applies when **Movement Type** is in _VelocityTracking_ mode. |
3232
| **Angular Velocity Scale** | Scale factor Unity applies to the tracked angular velocity while updating the `Rigidbody` when tracking the rotation of the Interactor.<br />Only applies when **Movement Type** is in _Velocity Tracking_ mode. |
33-
| **Throw On Detach** | Enable to have this object inherit the velocity of the Interactor when released. |
33+
| **Throw On Detach** | Enable to have this object inherit the velocity of the Interactor when released. This is not supported for a kinematic Rigidbody. |
3434
| **Throw Smoothing Duration** | Time period to average thrown velocity over. |
3535
| **Throw Smoothing Curve** | The curve to use to weight thrown velocity smoothing (most recent frames to the right). |
3636
| **Throw Velocity Scale** | Scale factor Unity applies to this object's velocity inherited from the Interactor when released. |

Editor/Interaction/Interactables/XRGrabInteractableEditor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ protected static class Contents
9898
/// <summary><see cref="GUIContent"/> for <see cref="XRGrabInteractable.tightenRotation"/>.</summary>
9999
public static readonly GUIContent tightenRotation = EditorGUIUtility.TrTextContent("Tighten Rotation", "Reduces the maximum follow rotation difference when using smoothing. The value ranges from 0 meaning no bias in the smoothed follow rotation, to 1 meaning effectively no smoothing at all.");
100100
/// <summary><see cref="GUIContent"/> for <see cref="XRGrabInteractable.throwOnDetach"/>.</summary>
101-
public static readonly GUIContent throwOnDetach = EditorGUIUtility.TrTextContent("Throw On Detach", "Whether this object inherits the velocity of the Interactor when released.");
101+
public static readonly GUIContent throwOnDetach = EditorGUIUtility.TrTextContent("Throw On Detach", "Whether this object inherits the velocity of the Interactor when released. This is not supported for a kinematic Rigidbody.");
102102
/// <summary><see cref="GUIContent"/> for <see cref="XRGrabInteractable.throwSmoothingDuration"/>.</summary>
103103
public static readonly GUIContent throwSmoothingDuration = EditorGUIUtility.TrTextContent("Throw Smoothing Duration", "Time period to average thrown velocity over.");
104104
/// <summary><see cref="GUIContent"/> for <see cref="XRGrabInteractable.throwSmoothingCurve"/>.</summary>
@@ -116,7 +116,7 @@ protected static class Contents
116116

117117
/// <summary>Message for non-uniformly scaled parent.</summary>
118118
public static readonly string nonUniformScaledParentWarning = "When a child object has a non-uniformly scaled parent and is rotated relative to that parent, it may appear skewed. To avoid this, use uniform scale in all parents' Transform of this object.";
119-
119+
120120
/// <summary>Array of type <see cref="GUIContent"/> for the options shown in the popup for <see cref="XRGrabInteractable.attachPointCompatibilityMode"/>.</summary>
121121
public static readonly GUIContent[] attachPointCompatibilityModeOptions =
122122
{

Editor/Interaction/Interactors/XRBaseControllerInteractorEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ protected virtual void VerifyControllerPresent()
242242
foreach (var targetObject in serializedObject.targetObjects)
243243
{
244244
var interactor = (XRBaseControllerInteractor)targetObject;
245-
if (interactor.GetComponentInParent<XRBaseController>() == null)
245+
if (interactor.FindControllerComponent() == null)
246246
{
247247
EditorGUILayout.HelpBox(BaseControllerContents.missingRequiredController, MessageType.Warning, true);
248248
break;

Runtime/Inputs/Simulation/XRDeviceSimulator.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,5 +1959,31 @@ static InputAction GetInputAction(InputActionReference actionReference)
19591959
return actionReference != null ? actionReference.action : null;
19601960
#pragma warning restore IDE0031
19611961
}
1962+
1963+
internal static unsafe bool TryExecuteCommand(InputDeviceCommand* commandPtr, out long result)
1964+
{
1965+
// This is a utility method called by XRSimulatedHMD and XRSimulatedController
1966+
// since both devices share the same command handling.
1967+
// This replicates the logic in XRToISXDevice::IOCTL (XRInputToISX.cpp).
1968+
var type = commandPtr->type;
1969+
if (type == RequestSyncCommand.Type)
1970+
{
1971+
// The state is maintained by XRDeviceSimulator, so no need for any change
1972+
// when focus is regained. Returning success instructs Input System to not
1973+
// reset the device.
1974+
result = InputDeviceCommand.GenericSuccess;
1975+
return true;
1976+
}
1977+
1978+
if (type == QueryCanRunInBackground.Type)
1979+
{
1980+
((QueryCanRunInBackground*)commandPtr)->canRunInBackground = true;
1981+
result = InputDeviceCommand.GenericSuccess;
1982+
return true;
1983+
}
1984+
1985+
result = default;
1986+
return false;
1987+
}
19621988
}
19631989
}

Runtime/Inputs/Simulation/XRSimulatedController.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using UnityEngine.InputSystem.Controls;
22
using UnityEngine.InputSystem.Layouts;
3+
using UnityEngine.InputSystem.LowLevel;
34
using UnityEngine.Scripting;
45

56
namespace UnityEngine.XR.Interaction.Toolkit.Inputs.Simulation
@@ -120,5 +121,13 @@ protected override void FinishSetup()
120121
batteryLevel = GetChildControl<AxisControl>(nameof(batteryLevel));
121122
userPresence = GetChildControl<ButtonControl>(nameof(userPresence));
122123
}
124+
125+
/// <inheritdoc />
126+
protected override unsafe long ExecuteCommand(InputDeviceCommand* commandPtr)
127+
{
128+
return XRDeviceSimulator.TryExecuteCommand(commandPtr, out var result)
129+
? result
130+
: base.ExecuteCommand(commandPtr);
131+
}
123132
}
124133
}

Runtime/Inputs/Simulation/XRSimulatedHMD.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using UnityEngine.InputSystem.Layouts;
2+
using UnityEngine.InputSystem.LowLevel;
23
using UnityEngine.InputSystem.XR;
34
using UnityEngine.Scripting;
45

@@ -11,5 +12,12 @@ namespace UnityEngine.XR.Interaction.Toolkit.Inputs.Simulation
1112
[Preserve]
1213
public class XRSimulatedHMD : XRHMD
1314
{
15+
/// <inheritdoc />
16+
protected override unsafe long ExecuteCommand(InputDeviceCommand* commandPtr)
17+
{
18+
return XRDeviceSimulator.TryExecuteCommand(commandPtr, out var result)
19+
? result
20+
: base.ExecuteCommand(commandPtr);
21+
}
1422
}
1523
}

Runtime/Interaction/Interactables/XRGrabInteractable.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -618,13 +618,11 @@ void PerformKinematicUpdate(XRInteractionUpdateOrder.UpdatePhase updatePhase)
618618
var position = m_AttachPointCompatibilityMode == AttachPointCompatibilityMode.Default
619619
? m_TargetWorldPosition
620620
: m_TargetWorldPosition - m_Rigidbody.worldCenterOfMass + m_Rigidbody.position;
621-
m_Rigidbody.velocity = Vector3.zero;
622621
m_Rigidbody.MovePosition(position);
623622
}
624623

625624
if (m_TrackRotation)
626625
{
627-
m_Rigidbody.angularVelocity = Vector3.zero;
628626
m_Rigidbody.MoveRotation(m_TargetWorldRotation);
629627
}
630628
}
@@ -736,7 +734,7 @@ protected virtual void Grab()
736734
var thisTransform = transform;
737735
m_OriginalSceneParent = thisTransform.parent;
738736
thisTransform.SetParent(null);
739-
737+
740738
UpdateCurrentMovementType();
741739
SetupRigidbodyGrab(m_Rigidbody);
742740

@@ -797,6 +795,12 @@ protected virtual void Detach()
797795
{
798796
if (m_ThrowOnDetach)
799797
{
798+
if (m_Rigidbody.isKinematic)
799+
{
800+
Debug.LogWarning("Cannot throw a kinematic Rigidbody since updating the velocity and angular velocity of a kinematic Rigidbody is not supported. Disable Throw On Detach or Is Kinematic to fix this issue.", this);
801+
return;
802+
}
803+
800804
m_Rigidbody.velocity = m_DetachVelocity;
801805
m_Rigidbody.angularVelocity = m_DetachAngularVelocity;
802806
}
@@ -836,7 +840,7 @@ protected virtual void SetupRigidbodyDrop(Rigidbody rigidbody)
836840
rigidbody.useGravity = m_UsedGravity;
837841
rigidbody.drag = m_OldDrag;
838842
rigidbody.angularDrag = m_OldAngularDrag;
839-
843+
840844
if (!isSelected)
841845
m_Rigidbody.useGravity |= m_ForceGravityOnDetach;
842846
}

Runtime/Interaction/Interactors/Visual/XRInteractorLineVisual.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,18 @@ public float snapThresholdDistance
175175
/// <summary>
176176
/// Stores the reticle that appears at the end of the line when it is valid.
177177
/// </summary>
178+
/// <remarks>
179+
/// Unity will instantiate it while playing when it is a Prefab asset.
180+
/// </remarks>
178181
public GameObject reticle
179182
{
180183
get => m_Reticle;
181-
set => m_Reticle = value;
184+
set
185+
{
186+
m_Reticle = value;
187+
if (Application.isPlaying)
188+
SetupReticle();
189+
}
182190
}
183191

184192
[SerializeField]
@@ -251,9 +259,7 @@ protected void Awake()
251259
{
252260
m_LineRenderable = GetComponent<ILineRenderable>();
253261

254-
if (m_Reticle != null)
255-
m_Reticle.SetActive(false);
256-
262+
SetupReticle();
257263
ClearLineRenderer();
258264
UpdateSettings();
259265
}
@@ -514,6 +520,18 @@ bool TryFindLineRenderer()
514520
return true;
515521
}
516522

523+
void SetupReticle()
524+
{
525+
if (m_Reticle == null)
526+
return;
527+
528+
// Instantiate if the reticle is a Prefab asset rather than a scene GameObject
529+
if (!m_Reticle.scene.IsValid())
530+
m_Reticle = Instantiate(m_Reticle);
531+
532+
m_Reticle.SetActive(false);
533+
}
534+
517535
/// <inheritdoc />
518536
public bool AttachCustomReticle(GameObject reticleInstance)
519537
{

0 commit comments

Comments
 (0)