|
1 | 1 | // ENABLE_VR is not defined on Game Core but the assembly is available with limited features when the XR module is enabled. |
2 | 2 | #if ENABLE_VR || UNITY_GAMECORE |
3 | 3 | using System; |
| 4 | +using System.Collections; |
4 | 5 | using System.Collections.Generic; |
5 | 6 | using System.Runtime.InteropServices; |
6 | 7 | using NUnit.Framework; |
|
11 | 12 | using UnityEngine.InputSystem.LowLevel; |
12 | 13 | using UnityEngine.InputSystem.Utilities; |
13 | 14 | using UnityEngine.InputSystem.XR; |
| 15 | +using UnityEngine.TestTools; |
14 | 16 | using UnityEngine.XR; |
15 | 17 |
|
16 | 18 | using Usages = UnityEngine.InputSystem.CommonUsages; |
@@ -629,6 +631,57 @@ public void Components_TrackedPoseDriver_DoesNotEnableOrDisableReferenceActions( |
629 | 631 | Assert.That(trackingStateInput.action.enabled, Is.False); |
630 | 632 | } |
631 | 633 |
|
| 634 | + [UnityTest] |
| 635 | + [Category("Components")] |
| 636 | + public IEnumerator LateAddedXRControllerCanLinkTrackedPoseDriver() |
| 637 | + { |
| 638 | + var go = new GameObject(); |
| 639 | + var tpd = go.AddComponent<TrackedPoseDriver>(); |
| 640 | + tpd.updateType = TrackedPoseDriver.UpdateType.UpdateAndBeforeRender; |
| 641 | + tpd.trackingType = TrackedPoseDriver.TrackingType.RotationAndPosition; |
| 642 | + tpd.ignoreTrackingState = false; |
| 643 | + var transform = tpd.transform; |
| 644 | + |
| 645 | + var positionAction = new InputAction(binding: "<XRController>/devicePosition"); |
| 646 | + var rotationAction = new InputAction(binding: "<XRController>/deviceRotation"); |
| 647 | + var trackingStateAction = new InputAction(binding: "<XRController>/trackingState"); |
| 648 | + tpd.positionInput = new InputActionProperty(positionAction); |
| 649 | + tpd.rotationInput = new InputActionProperty(rotationAction); |
| 650 | + tpd.trackingStateInput = new InputActionProperty(trackingStateAction); |
| 651 | + |
| 652 | + yield return null; |
| 653 | + |
| 654 | + Assert.That(positionAction.controls.Count, Is.EqualTo(0)); |
| 655 | + Assert.That(rotationAction.controls.Count, Is.EqualTo(0)); |
| 656 | + |
| 657 | + var device = InputSystem.AddDevice<XRController>(); |
| 658 | + InputSystem.AddDeviceUsage(device, "RightHand"); |
| 659 | + |
| 660 | + yield return null; |
| 661 | + |
| 662 | + Assert.That(positionAction.controls.Count, Is.EqualTo(1)); |
| 663 | + Assert.That(rotationAction.controls.Count, Is.EqualTo(1)); |
| 664 | + |
| 665 | + var position = new Vector3(1f, 2f, 3f); |
| 666 | + var rotation = new Quaternion(0.09853293f, 0.09853293f, 0.09853293f, 0.9853293f); |
| 667 | + using (StateEvent.From(device, out var stateEvent)) |
| 668 | + { |
| 669 | + device.devicePosition.WriteValueIntoEvent(position, stateEvent); |
| 670 | + device.deviceRotation.WriteValueIntoEvent(rotation, stateEvent); |
| 671 | + device.trackingState.WriteValueIntoEvent((int)(InputTrackingState.Position | InputTrackingState.Rotation), stateEvent); |
| 672 | + |
| 673 | + transform.position = Vector3.zero; |
| 674 | + transform.rotation = Quaternion.identity; |
| 675 | + InputSystem.QueueEvent(stateEvent); |
| 676 | + InputSystem.Update(InputUpdateType.Dynamic); |
| 677 | + } |
| 678 | + |
| 679 | + yield return null; |
| 680 | + |
| 681 | + Assert.That(transform.position, Is.EqualTo(position)); |
| 682 | + Assert.That(transform.rotation, Is.EqualTo(rotation)); |
| 683 | + } |
| 684 | + |
632 | 685 | [Test] |
633 | 686 | [Category("Components")] |
634 | 687 | public void Components_TrackedPoseDriver_RequiresResolvedTrackingStateBindings() |
|
0 commit comments