Exemplo n.º 1
0
        public IEnumerator RayInteractorCanReleaseInteractableAfterHoverToSelectWhenGripping([ValueSource(nameof(s_SelectActionTriggers))] XRBaseControllerInteractor.InputTriggerType selectActionTrigger)
        {
            var manager    = TestUtilities.CreateInteractionManager();
            var interactor = TestUtilities.CreateRayInteractor();

            interactor.transform.position  = Vector3.zero;
            interactor.transform.forward   = Vector3.forward;
            interactor.hoverToSelect       = true;
            interactor.hoverTimeToSelect   = 0.2f;
            interactor.selectActionTrigger = selectActionTrigger;
            var interactable = TestUtilities.CreateSimpleInteractable();

            interactable.transform.position = interactor.transform.position + interactor.transform.forward * 5.0f;

            var controller      = interactor.GetComponent <XRBaseController>();
            var controllerState = new XRControllerState(0f, Vector3.zero, Quaternion.identity, false, false, false);

            controller.SetControllerState(controllerState);

            yield return(new WaitForSeconds(0.1f));

            // Hasn't met duration threshold yet
            Assert.That(controllerState.selectInteractionState.active, Is.False);
            Assert.That(interactable.isHovered, Is.True);
            Assert.That(interactable.isSelected, Is.False);
            Assert.That(interactor.isSelectActive, Is.False);

            yield return(new WaitForSeconds(0.2f));

            // Hovered for long enough
            Assert.That(controllerState.selectInteractionState.active, Is.False);
            Assert.That(interactable.isHovered, Is.True);
            Assert.That(interactable.isSelected, Is.True);
            Assert.That(interactor.isSelectActive, Is.True);

            // Press Grip
            controllerState.selectInteractionState = new InteractionState {
                active = true, activatedThisFrame = true
            };

            yield return(null);

            Assert.That(controllerState.selectInteractionState.active, Is.True);
            Assert.That(controllerState.selectInteractionState.activatedThisFrame, Is.True);
            Assert.That(interactable.isHovered, Is.True);
            Assert.That(interactable.isSelected, Is.True);
            Assert.That(interactor.isSelectActive, Is.True);

            interactor.hoverToSelect = false;
            controllerState.selectInteractionState = new InteractionState {
                active = true
            };

            yield return(null);

            // This table summarizes what must be done by a user to drop the Interactable
            // when hoverToSelect is disabled. It depends on whether the Select (i.e. Grip)
            // is pressed after the Interactable is automatically selected from hoverToSelect.
            // |Type       |To drop when Grip is false|To drop when Grip is true after auto Select|
            // |-----------|--------------------------|-------------------------------------------|
            // |State      |Nothing (will drop)       |Release Grip                               |
            // |StateChange|Press then Release Grip   |Release Grip                               |
            // |Toggle     |Press Grip                |Nothing (will drop since already toggled)  |
            // |Sticky     |Press then Release Grip   |Release Grip                               |
            Assert.That(controllerState.selectInteractionState.active, Is.True);
            Assert.That(interactable.isHovered, Is.True);
            switch (selectActionTrigger)
            {
            case XRBaseControllerInteractor.InputTriggerType.State:
            case XRBaseControllerInteractor.InputTriggerType.StateChange:
            case XRBaseControllerInteractor.InputTriggerType.Sticky:
                Assert.That(interactable.isSelected, Is.True);
                Assert.That(interactor.isSelectActive, Is.True);
                break;

            case XRBaseControllerInteractor.InputTriggerType.Toggle:
                Assert.That(interactable.isSelected, Is.False);
                Assert.That(interactor.isSelectActive, Is.False);
                break;
            }

            // Release Grip
            controllerState.selectInteractionState = new InteractionState {
                active = false, deactivatedThisFrame = true
            };

            yield return(null);

            Assert.That(controllerState.selectInteractionState.active, Is.False);
            Assert.That(controllerState.selectInteractionState.deactivatedThisFrame, Is.True);
            Assert.That(interactable.isHovered, Is.True);
            Assert.That(interactable.isSelected, Is.False);
            Assert.That(interactor.isSelectActive, Is.False);
        }
Exemplo n.º 2
0
        public IEnumerator RayInteractorCanSelectAndReleaseInteractable([ValueSource(nameof(s_SelectActionTriggers))] XRBaseControllerInteractor.InputTriggerType selectActionTrigger)
        {
            var manager    = TestUtilities.CreateInteractionManager();
            var interactor = TestUtilities.CreateRayInteractor();

            interactor.transform.position  = Vector3.zero;
            interactor.transform.forward   = Vector3.forward;
            interactor.selectActionTrigger = selectActionTrigger;
            var interactable = TestUtilities.CreateSimpleInteractable();

            interactable.transform.position = interactor.transform.position + interactor.transform.forward * 5.0f;

            var controller      = interactor.GetComponent <XRBaseController>();
            var controllerState = new XRControllerState(0f, Vector3.zero, Quaternion.identity, false, false, false);

            controller.SetControllerState(controllerState);

            yield return(new WaitForFixedUpdate());

            yield return(null);

            Assert.That(controllerState.selectInteractionState.active, Is.False);
            Assert.That(interactable.isHovered, Is.True);
            Assert.That(interactable.isSelected, Is.False);
            Assert.That(interactor.isSelectActive, Is.False);

            // Press Grip
            controllerState.selectInteractionState = new InteractionState {
                active = true, activatedThisFrame = true
            };

            yield return(null);

            Assert.That(controllerState.selectInteractionState.active, Is.True);
            Assert.That(controllerState.selectInteractionState.activatedThisFrame, Is.True);
            Assert.That(interactable.isHovered, Is.True);
            Assert.That(interactable.isSelected, Is.True);
            Assert.That(interactor.isSelectActive, Is.True);

            // Release Grip
            controllerState.selectInteractionState = new InteractionState {
                active = false, deactivatedThisFrame = true
            };

            yield return(null);

            Assert.That(controllerState.selectInteractionState.active, Is.False);
            Assert.That(controllerState.selectInteractionState.deactivatedThisFrame, Is.True);
            Assert.That(interactable.isHovered, Is.True);
            switch (selectActionTrigger)
            {
            case XRBaseControllerInteractor.InputTriggerType.State:
            case XRBaseControllerInteractor.InputTriggerType.StateChange:
                Assert.That(interactable.isSelected, Is.False);
                Assert.That(interactor.isSelectActive, Is.False);
                break;

            case XRBaseControllerInteractor.InputTriggerType.Toggle:
            case XRBaseControllerInteractor.InputTriggerType.Sticky:
                Assert.That(interactable.isSelected, Is.True);
                Assert.That(interactor.isSelectActive, Is.True);
                break;
            }

            // Press Grip again
            controllerState.selectInteractionState = new InteractionState {
                active = true, activatedThisFrame = true
            };

            yield return(null);

            Assert.That(controllerState.selectInteractionState.active, Is.True);
            Assert.That(controllerState.selectInteractionState.activatedThisFrame, Is.True);
            Assert.That(interactable.isHovered, Is.True);
            switch (selectActionTrigger)
            {
            case XRBaseControllerInteractor.InputTriggerType.State:
            case XRBaseControllerInteractor.InputTriggerType.StateChange:
            case XRBaseControllerInteractor.InputTriggerType.Sticky:
                Assert.That(interactable.isSelected, Is.True);
                Assert.That(interactor.isSelectActive, Is.True);
                break;

            case XRBaseControllerInteractor.InputTriggerType.Toggle:
                Assert.That(interactable.isSelected, Is.False);
                Assert.That(interactor.isSelectActive, Is.False);
                break;
            }

            // Release Grip again
            controllerState.selectInteractionState = new InteractionState {
                active = false, deactivatedThisFrame = true
            };

            yield return(null);

            Assert.That(controllerState.selectInteractionState.active, Is.False);
            Assert.That(controllerState.selectInteractionState.deactivatedThisFrame, Is.True);
            Assert.That(interactable.isHovered, Is.True);
            Assert.That(interactable.isSelected, Is.False);
            Assert.That(interactor.isSelectActive, Is.False);
        }
Exemplo n.º 3
0
 private void Awake()
 {
     interactor          = GetComponent <XRBaseControllerInteractor>();
     interactionManager  = interactor.interactionManager;
     originalTriggerType = interactor.selectActionTrigger;
 }