public void Actions_CanGetCompletionPercentageOfTimeoutOnInteraction() { var gamepad = InputSystem.AddDevice <Gamepad>(); var actionWithoutInteraction = new InputAction(type: InputActionType.Button, binding: "<Gamepad>/buttonSouth"); var holdAction = new InputAction(binding: "<Gamepad>/buttonSouth", interactions: "hold(duration=2)"); var tapAction = new InputAction(binding: "<Gamepad>/buttonSouth", interactions: "tap(duration=2)"); var multiTapAction = new InputAction(binding: "<Gamepad>/buttonSouth", interactions: "multitap(tapCount=2,tapTime=2,tapDelay=2)"); actionWithoutInteraction.Enable(); holdAction.Enable(); tapAction.Enable(); multiTapAction.Enable(); Assert.That(actionWithoutInteraction.GetTimeoutCompletionPercentage(), Is.EqualTo(0).Within(0.0001)); Assert.That(holdAction.GetTimeoutCompletionPercentage(), Is.EqualTo(0).Within(0.0001)); Assert.That(tapAction.GetTimeoutCompletionPercentage(), Is.EqualTo(0).Within(0.0001)); Assert.That(multiTapAction.GetTimeoutCompletionPercentage(), Is.EqualTo(0).Within(0.0001)); currentTime = 1; Press(gamepad.buttonSouth); Assert.That(actionWithoutInteraction.GetTimeoutCompletionPercentage(), Is.EqualTo(1).Within(0.0001)); Assert.That(holdAction.GetTimeoutCompletionPercentage(), Is.EqualTo(0).Within(0.0001)); Assert.That(tapAction.GetTimeoutCompletionPercentage(), Is.EqualTo(0).Within(0.0001)); Assert.That(multiTapAction.GetTimeoutCompletionPercentage(), Is.EqualTo(0).Within(0.0001)); currentTime = 2; Assert.That(actionWithoutInteraction.GetTimeoutCompletionPercentage(), Is.EqualTo(1).Within(0.0001)); Assert.That(holdAction.GetTimeoutCompletionPercentage(), Is.EqualTo(0.5).Within(0.0001)); Assert.That(tapAction.GetTimeoutCompletionPercentage(), Is.EqualTo(0.5).Within(0.0001)); Assert.That(multiTapAction.GetTimeoutCompletionPercentage(), Is.EqualTo(1f / (3f * 2f)).Within(0.0001)); // Note that just advancing time is enough to advance towards completion. No InputSystem.Update() // is required. currentTime = 4; Assert.That(actionWithoutInteraction.GetTimeoutCompletionPercentage(), Is.EqualTo(1).Within(0.0001)); Assert.That(holdAction.GetTimeoutCompletionPercentage(), Is.EqualTo(1).Within(0.0001)); Assert.That(tapAction.GetTimeoutCompletionPercentage(), Is.EqualTo(1).Within(0.0001)); // Has not yet canceled because we haven't updated. Assert.That(multiTapAction.GetTimeoutCompletionPercentage(), Is.EqualTo(2f / (3f * 2f)).Within(0.0001)); InputSystem.Update(); Assert.That(actionWithoutInteraction.GetTimeoutCompletionPercentage(), Is.EqualTo(1).Within(0.0001)); Assert.That(holdAction.GetTimeoutCompletionPercentage(), Is.EqualTo(1).Within(0.0001)); Assert.That(tapAction.GetTimeoutCompletionPercentage(), Is.EqualTo(0).Within(0.0001)); // Has cancelled now. Assert.That(multiTapAction.GetTimeoutCompletionPercentage(), Is.EqualTo(0).Within(0.0001)); // Also cancelled because we went past tap delay. Release(gamepad.buttonSouth); Assert.That(actionWithoutInteraction.GetTimeoutCompletionPercentage(), Is.EqualTo(0).Within(0.0001)); Assert.That(holdAction.GetTimeoutCompletionPercentage(), Is.EqualTo(0).Within(0.0001)); Assert.That(tapAction.GetTimeoutCompletionPercentage(), Is.EqualTo(0).Within(0.0001)); Assert.That(multiTapAction.GetTimeoutCompletionPercentage(), Is.EqualTo(0).Within(0.0001)); // Check with multiple timeouts on MultiTap. currentTime = 6; Press(gamepad.buttonSouth); Assert.That(multiTapAction.GetTimeoutCompletionPercentage(), Is.EqualTo(0).Within(0.0001)); currentTime = 7; Release(gamepad.buttonSouth); // Note the system now treats the first timeout as complete. Assert.That(multiTapAction.GetTimeoutCompletionPercentage(), Is.EqualTo(2f / (3f * 2f)).Within(0.0001)); currentTime = 8; Press(gamepad.buttonSouth); // Same here. Assert.That(multiTapAction.GetTimeoutCompletionPercentage(), Is.EqualTo(4f / (3f * 2f)).Within(0.0001)); currentTime = 10; Assert.That(multiTapAction.GetTimeoutCompletionPercentage(), Is.EqualTo(1).Within(0.0001)); }