public void Controls_CanQueueValueChange() { var gamepad = InputSystem.AddDevice <Gamepad>(); gamepad.leftTrigger.QueueValueChange(0.123f); Assert.That(gamepad.leftTrigger.ReadValue(), Is.EqualTo(0).Within(0.00001)); InputSystem.Update(); Assert.That(gamepad.leftTrigger.ReadValue(), Is.EqualTo(0.123).Within(0.00001)); gamepad.leftTrigger.QueueValueChange(0.234f); gamepad.leftTrigger.QueueValueChange(0.345f); Assert.That(gamepad.leftTrigger.ReadValue(), Is.EqualTo(0.123).Within(0.00001)); InputSystem.Update(); Assert.That(gamepad.leftTrigger.ReadValue(), Is.EqualTo(0.345).Within(0.00001)); }
public void Controls_CanEvaluateMagnitude() { var gamepad = InputSystem.AddDevice <Gamepad>(); InputSystem.QueueStateEvent(gamepad, new GamepadState { leftStick = new Vector2(0.5f, 0.5f), leftTrigger = 0.5f }.WithButton(GamepadButton.South)); InputSystem.Update(); Assert.That(gamepad.rightStick.EvaluateMagnitude(), Is.EqualTo(0).Within(0.00001)); Assert.That(gamepad.leftStick.EvaluateMagnitude(), Is.EqualTo(new StickDeadzoneProcessor().Process(new Vector2(0.5f, 0.5f)).magnitude).Within(0.00001)); Assert.That(gamepad.buttonNorth.EvaluateMagnitude(), Is.EqualTo(0).Within(0.00001)); Assert.That(gamepad.buttonSouth.EvaluateMagnitude(), Is.EqualTo(1).Within(0.00001)); Assert.That(gamepad.leftTrigger.EvaluateMagnitude(), Is.EqualTo(0.5).Within(0.00001)); }
public void Controls_CanWriteValueIntoDeltaStateEvents() { var gamepad = InputSystem.AddDevice <Gamepad>(); var receivedCalls = 0; InputSystem.onEvent += (eventPtr, device) => { ++receivedCalls; gamepad.leftTrigger.WriteValueIntoEvent(0.1234f, eventPtr); }; InputSystem.QueueDeltaStateEvent(gamepad.leftTrigger, 0.8765f); InputSystem.Update(); Assert.That(receivedCalls, Is.EqualTo(1)); Assert.That(gamepad.leftTrigger.ReadValue(), Is.EqualTo(0.1234).Within(0.000001)); }
public void Events_CanPreventEventsFromBeingProcessed() { InputSystem.onEvent += inputEvent => { // If we mark the event handled, the system should skip it and not // let it go to the device. inputEvent.handled = true; }; var device = InputSystem.AddDevice <Gamepad>(); InputSystem.QueueStateEvent(device, new GamepadState { rightTrigger = 0.45f }); InputSystem.Update(); Assert.That(device.rightTrigger.ReadValue(), Is.EqualTo(0.0).Within(0.00001)); }
public void Events_CanHandleStateNotAlignedTo4ByteBoundary() { Debug.Assert(UnsafeUtility.SizeOf <StateWith2Bytes>() == 2); var device = InputSystem.AddDevice <DeviceWith2ByteState>(); InputSystem.QueueStateEvent(device, new StateWith2Bytes()); InputSystem.QueueStateEvent(device, new StateWith2Bytes()); InputSystem.onEvent += eventPtr => { // Event addresses must be 4-byte aligned but sizeInBytes must not have been altered. Assert.That(eventPtr.data.ToInt64() % 4, Is.EqualTo(0)); Assert.That(eventPtr.sizeInBytes, Is.EqualTo(StateEvent.GetEventSizeWithPayload <StateWith2Bytes>())); }; InputSystem.Update(); }
public void Events_IfOldStateEventIsSentToDevice_IsIgnored_ExceptIfEventIsHandledByIInputStateCallbackReceiver() { var device = InputSystem.AddDevice <Touchscreen>(); // Sanity check. Assert.That(device is IInputStateCallbackReceiver, "Test assumes that Touchscreen implements IInputStateCallbackReceiver"); InputSystem.QueueStateEvent(device, new TouchState { touchId = 1, phase = TouchPhase.Began, position = new Vector2(0.123f, 0.234f) }, 2); InputSystem.QueueStateEvent(device, new TouchState { touchId = 1, phase = TouchPhase.Moved, position = new Vector2(0.234f, 0.345f) }, 1); // Goes back in time. InputSystem.Update(); Assert.That(device.lastUpdateTime, Is.EqualTo(2).Within(0.00001)); Assert.That(device.position.ReadValue(), Is.EqualTo(new Vector2(0.234f, 0.345f)).Using(Vector2EqualityComparer.Instance)); }
public void Controls_CanTurnControlPathIntoHumanReadableText() { Assert.That(InputControlPath.ToHumanReadableString("*/{PrimaryAction}"), Is.EqualTo("PrimaryAction [Any]")); Assert.That(InputControlPath.ToHumanReadableString("<Gamepad>/leftStick"), Is.EqualTo("Left Stick [Gamepad]")); Assert.That(InputControlPath.ToHumanReadableString("<Gamepad>/leftStick/x"), Is.EqualTo("Left Stick/X [Gamepad]")); Assert.That(InputControlPath.ToHumanReadableString("<XRController>{LeftHand}/position"), Is.EqualTo("position [LeftHand XRController]")); Assert.That(InputControlPath.ToHumanReadableString("*/leftStick"), Is.EqualTo("leftStick [Any]")); Assert.That(InputControlPath.ToHumanReadableString("*/{PrimaryMotion}/x"), Is.EqualTo("PrimaryMotion/x [Any]")); Assert.That(InputControlPath.ToHumanReadableString("<Gamepad>/buttonSouth"), Is.EqualTo("Button South [Gamepad]")); Assert.That(InputControlPath.ToHumanReadableString("<XInputController>/buttonSouth"), Is.EqualTo("A [Xbox Controller]")); Assert.That(InputControlPath.ToHumanReadableString("<Touchscreen>/touch4/tap"), Is.EqualTo("Touch #4/Tap [Touchscreen]")); Assert.That( InputControlPath.ToHumanReadableString("<Gamepad>/buttonSouth", InputControlPath.HumanReadableStringOptions.OmitDevice), Is.EqualTo("Button South")); Assert.That( InputControlPath.ToHumanReadableString("*/{PrimaryAction}", InputControlPath.HumanReadableStringOptions.OmitDevice), Is.EqualTo("PrimaryAction")); }
public void Events_CanListenForWhenAllEventsHaveBeenProcessed() { var receivedCalls = 0; void callback() => ++ receivedCalls; InputSystem.onAfterUpdate += callback; InputSystem.Update(); Assert.That(receivedCalls, Is.EqualTo(1)); receivedCalls = 0; InputSystem.onAfterUpdate -= callback; InputSystem.Update(); Assert.That(receivedCalls, Is.Zero); }
public void Events_AreProcessedInOrderTheyAreQueuedIn() { const double kFirstTime = 0.5; const double kSecondTime = 1.5; const double kThirdTime = 2.5; var receivedCalls = 0; var receivedFirstTime = 0.0; var receivedSecondTime = 0.0; var receivedThirdTime = 0.0; InputSystem.onEvent += (inputEvent, _) => { ++receivedCalls; if (receivedCalls == 1) { receivedFirstTime = inputEvent.time; } else if (receivedCalls == 2) { receivedSecondTime = inputEvent.time; } else { receivedThirdTime = inputEvent.time; } }; var device = InputSystem.AddDevice <Gamepad>(); InputSystem.QueueStateEvent(device, new GamepadState(), kSecondTime); InputSystem.QueueStateEvent(device, new GamepadState(), kFirstTime); InputSystem.QueueStateEvent(device, new GamepadState(), kThirdTime); InputSystem.Update(); Assert.That(receivedCalls, Is.EqualTo(3)); Assert.That(receivedFirstTime, Is.EqualTo(kSecondTime).Within(0.00001)); Assert.That(receivedSecondTime, Is.EqualTo(kFirstTime).Within(0.00001)); Assert.That(receivedThirdTime, Is.EqualTo(kThirdTime).Within(0.00001)); }
public void Events_EventBuffer_CanIterateEvents() { var gamepad = InputSystem.AddDevice <Gamepad>(); unsafe { using (StateEvent.From(gamepad, out var eventPtr)) using (var buffer = new InputEventBuffer(eventPtr, 1)) { Assert.That(buffer.eventCount, Is.EqualTo(1)); Assert.That(buffer.sizeInBytes, Is.EqualTo(InputEventBuffer.BufferSizeUnknown)); Assert.That(buffer.capacityInBytes, Is.Zero); Assert.That(buffer.bufferPtr, Is.EqualTo(eventPtr)); var events = buffer.ToArray(); Assert.That(events, Has.Length.EqualTo(1)); Assert.That(events[0], Is.EqualTo(eventPtr)); } } }
public void Controls_CanCustomizePressPointOfGamepadTriggers() { var json = @" { ""name"" : ""CustomGamepad"", ""extend"" : ""Gamepad"", ""controls"" : [ { ""name"" : ""rightTrigger"", ""parameters"" : ""pressPoint=0.2"" } ] } "; InputSystem.RegisterLayout(json); var gamepad = (Gamepad) new InputDeviceBuilder("CustomGamepad").Finish(); Assert.That(gamepad.rightTrigger.pressPoint, Is.EqualTo(0.2f).Within(0.0001f)); }
public void Events_WillNotReceiveEventsAgainstNonExistingDevices() { // Device IDs are looked up only *after* the system shows the event to us. var receivedCalls = 0; InputSystem.onEvent += (eventPtr, _) => { ++receivedCalls; }; var inputEvent = DeviceConfigurationEvent.Create(4, 1.0); InputSystem.QueueEvent(ref inputEvent); InputSystem.Update(); Assert.That(receivedCalls, Is.EqualTo(0)); }
public void Events_EventBuffer_CanAddEvents() { var gamepad = InputSystem.AddDevice <Gamepad>(); unsafe { InputEventPtr eventPtr; using (StateEvent.From(gamepad, out eventPtr)) using (var buffer = new InputEventBuffer()) { // Write two events into buffer. gamepad.leftStick.WriteValueInto(eventPtr, Vector2.one); eventPtr.id = 111; eventPtr.time = 123; eventPtr.handled = false; buffer.AppendEvent(eventPtr); gamepad.leftStick.WriteValueInto(eventPtr, Vector2.zero); eventPtr.id = 222; eventPtr.time = 234; eventPtr.handled = true; buffer.AppendEvent(eventPtr); Assert.That(buffer.eventCount, Is.EqualTo(2)); var events = buffer.ToArray(); Assert.That(events, Has.Length.EqualTo(2)); Assert.That(events[0].type, Is.EqualTo(new FourCC(StateEvent.Type))); Assert.That(events[1].type, Is.EqualTo(new FourCC(StateEvent.Type))); Assert.That(events[0].time, Is.EqualTo(123).Within(0.00001)); Assert.That(events[1].time, Is.EqualTo(234).Within(0.00001)); Assert.That(events[0].id, Is.EqualTo(111)); Assert.That(events[1].id, Is.EqualTo(222)); Assert.That(events[0].handled, Is.False); Assert.That(events[1].handled, Is.True); Assert.That(events[0].deviceId, Is.EqualTo(gamepad.id)); Assert.That(events[1].deviceId, Is.EqualTo(gamepad.id)); Assert.That(gamepad.leftStick.ReadUnprocessedValueFrom(events[0]), Is.EqualTo(Vector2.one)); Assert.That(gamepad.leftStick.ReadUnprocessedValueFrom(events[1]), Is.EqualTo(Vector2.zero)); } } }
public void Controls_DisplayNameDefaultsToControlName() { const string json = @" { ""name"" : ""MyDevice"", ""controls"" : [ { ""name"" : ""control"", ""layout"" : ""Button"" } ] } "; InputSystem.RegisterLayout(json); var setup = new InputDeviceBuilder("MyDevice"); var control = setup.GetControl("control"); Assert.That(control.displayName, Is.EqualTo("control")); }
public void Events_CanCreateDeltaStateEventFromControl() { var gamepad = InputSystem.AddDevice <Gamepad>(); Set(gamepad.buttonSouth, 1); Set(gamepad.buttonNorth, 1); Set(gamepad.leftTrigger, 0.123f); using (DeltaStateEvent.From(gamepad.buttonNorth, out var eventPtr)) { Assert.That(gamepad.buttonNorth.ReadValueFromEvent(eventPtr, out var val), Is.True); Assert.That(val, Is.EqualTo(1).Within(0.00001)); gamepad.buttonNorth.WriteValueIntoEvent(0f, eventPtr); InputSystem.QueueEvent(eventPtr); InputSystem.Update(); Assert.That(gamepad.buttonNorth.ReadValue(), Is.Zero); } }
public void Controls_DisplayNameDefaultsToControlName() { const string json = @" { ""name"" : ""MyDevice"", ""controls"" : [ { ""name"" : ""control"", ""layout"" : ""Button"" } ] } "; InputSystem.RegisterLayout(json); var control = InputDevice.Build <InputDevice>("MyDevice")["control"]; Assert.That(control.displayName, Is.EqualTo("control")); Assert.That(control.shortDisplayName, Is.Null); }
public void Controls_ReadingValueFromStateEvent_ReturnsDefaultValueForControlsNotPartOfEvent() { // Add one extra control with default state to Gamepad but // don't change its state format (so we can send it GamepadState // events without the extra control). const string json = @" { ""name"" : ""TestDevice"", ""extend"" : ""Gamepad"", ""controls"" : [ { ""name"" : ""extraControl"", ""layout"" : ""Axis"", ""defaultState"" : ""0.1234"" } ] } "; InputSystem.RegisterLayout(json); var device = InputSystem.AddDevice("TestDevice"); float?value = null; InputSystem.onEvent += eventPtr => { Assert.That(value, Is.Null); float eventValue; ((AxisControl)device["extraControl"]).ReadValueFromEvent(eventPtr, out eventValue); value = eventValue; }; InputSystem.QueueStateEvent(device, new GamepadState()); InputSystem.Update(); Assert.That(value, Is.Not.Null); Assert.That(value.Value, Is.EqualTo(0.1234).Within(0.00001)); }
public void Controls_CanReadValueFromStateEvents() { var gamepad = InputSystem.AddDevice <Gamepad>(); var receivedCalls = 0; InputSystem.onEvent += eventPtr => { ++receivedCalls; float value; Assert.IsTrue(gamepad.leftTrigger.ReadValueFromEvent(eventPtr, out value)); Assert.That(value, Is.EqualTo(0.234f).Within(0.00001)); }; InputSystem.QueueStateEvent(gamepad, new GamepadState { leftTrigger = 0.234f }); InputSystem.Update(); Assert.That(receivedCalls, Is.EqualTo(1)); }
public void Controls_CanHaveStickDeadzones() { const string json = @" { ""name"" : ""MyDevice"", ""extend"" : ""Gamepad"", ""controls"" : [ { ""name"" : ""leftStick"", ""processors"" : ""stickDeadzone(min=0.1,max=0.9)"" } ] } "; InputSystem.RegisterLayout(json); var device = (Gamepad)InputSystem.AddDevice("MyDevice"); ////NOTE: Unfortunately, this relies on an internal method ATM. var processor = device.leftStick.TryGetProcessor <StickDeadzoneProcessor>(); var firstState = new GamepadState { leftStick = new Vector2(0.05f, 0.05f) }; var secondState = new GamepadState { leftStick = new Vector2(0.5f, 0.5f) }; InputSystem.QueueStateEvent(device, firstState); InputSystem.Update(); Assert.That(device.leftStick.ReadValue(), Is.EqualTo(default(Vector2))); InputSystem.QueueStateEvent(device, secondState); InputSystem.Update(); Assert.That(device.leftStick.ReadValue(), Is.EqualTo(processor.Process(new Vector2(0.5f, 0.5f), device.leftStick))); }
public void Events_AreProcessedInBothFixedAndDynamicUpdateByDefault() { var mouse = InputSystem.AddDevice <Mouse>(); Assert.That(InputSystem.settings.updateMode, Is.EqualTo(InputSettings.UpdateMode.ProcessEventsInBothFixedAndDynamicUpdate)); Assert.That(InputSystem.s_Manager.m_StateBuffers.GetDoubleBuffersFor(InputUpdateType.Fixed).valid, Is.True); Assert.That(InputSystem.s_Manager.m_StateBuffers.GetDoubleBuffersFor(InputUpdateType.Dynamic).valid, Is.True); Assert.That(InputSystem.s_Manager.m_StateBuffers.GetDoubleBuffersFor(InputUpdateType.Manual).valid, Is.False); // Push event through in fixed update. InputSystem.QueueStateEvent(mouse, new MouseState().WithButton(MouseButton.Left)); InputSystem.Update(InputUpdateType.Fixed); Assert.That(mouse.leftButton.isPressed, Is.True); // Push event through in dynamic update. InputSystem.QueueStateEvent(mouse, new MouseState().WithButton(MouseButton.Right)); InputSystem.Update(InputUpdateType.Dynamic); Assert.That(mouse.leftButton.isPressed, Is.False); Assert.That(mouse.rightButton.isPressed, Is.True); }
public void Events_SendingStateToDeviceWithBeforeRenderEnabled_UpdatesDeviceInBeforeRender() { const string deviceJson = @" { ""name"" : ""CustomGamepad"", ""extend"" : ""Gamepad"", ""beforeRender"" : ""Update"" } "; InputSystem.RegisterLayout(deviceJson); var gamepad = (Gamepad)InputSystem.AddDevice("CustomGamepad"); var newState = new GamepadState { leftTrigger = 0.123f }; InputSystem.QueueStateEvent(gamepad, newState); InputSystem.Update(InputUpdateType.BeforeRender); Assert.That(gamepad.leftTrigger.ReadValue(), Is.EqualTo(0.123f).Within(0.000001)); }
public unsafe void Events_CanGetStatePointerFromEventThroughControl_EvenIfDeviceIsStateCallbackReceiver() { var touchscreen = InputSystem.AddDevice <Touchscreen>(); using (var trace = new InputEventTrace { deviceId = touchscreen.deviceId }) { trace.Enable(); BeginTouch(1, new Vector2(123, 234)); var statePtr = touchscreen.primaryTouch.position.GetStatePtrFromStateEvent(trace.ToArray()[0]); Assert.That(statePtr != null); // Attempt reading the position value from the touch event. Assert.That(touchscreen.primaryTouch.position.ReadValueFromState(statePtr), Is.EqualTo(new Vector2(123, 234)).Using(Vector2EqualityComparer.Instance)); // It only works with primaryTouch. See Touchscreen.GetStateOffsetForEvent for details. Assert.That(touchscreen.touches[1].position.GetStatePtrFromStateEvent(trace.ToArray()[0]) == null); } }
public unsafe void Controls_CanWriteValueFromObjectIntoState() { var gamepad = InputSystem.AddDevice <Gamepad>(); var tempBufferSize = (int)gamepad.stateBlock.alignedSizeInBytes; using (var tempBuffer = new NativeArray <byte>(tempBufferSize, Allocator.Temp)) { var tempBufferPtr = (byte *)NativeArrayUnsafeUtility.GetUnsafeReadOnlyPtr(tempBuffer); // The device is the first in the system so is guaranteed to start of offset 0 which // means we don't need to adjust the pointer here. Debug.Assert(gamepad.stateBlock.byteOffset == 0); gamepad.leftStick.WriteValueFromObjectIntoState(new Vector2(0.1234f, 0.5678f), tempBufferPtr); var leftStickXPtr = (float *)(tempBufferPtr + gamepad.leftStick.x.stateBlock.byteOffset); var leftStickYPtr = (float *)(tempBufferPtr + gamepad.leftStick.y.stateBlock.byteOffset); Assert.That(*leftStickXPtr, Is.EqualTo(0.1234).Within(0.00001)); Assert.That(*leftStickYPtr, Is.EqualTo(0.5678).Within(0.00001)); } }
public void Events_CanSendSmallerStateToDeviceWithLargerState() { const string json = @" { ""name"" : ""TestLayout"", ""extend"" : ""CustomDevice"", ""controls"" : [ { ""name"" : ""extra"", ""layout"" : ""Button"" } ] } "; InputSystem.RegisterLayout <CustomDevice>(); InputSystem.RegisterLayout(json); var device = (CustomDevice)InputSystem.AddDevice("TestLayout"); InputSystem.QueueStateEvent(device, new CustomDeviceState { axis = 0.5f }); InputSystem.Update(); Assert.That(device.axis.ReadValue(), Is.EqualTo(0.5).Within(0.000001)); }
public void Events_CanListenForWhenAllEventsHaveBeenProcessed() { InputUpdateType? receivedUpdateType = null; Action <InputUpdateType> callback = type => { Assert.That(receivedUpdateType, Is.Null); receivedUpdateType = type; }; InputSystem.onAfterUpdate += callback; InputSystem.Update(InputUpdateType.Dynamic); Assert.That(receivedUpdateType, Is.EqualTo(InputUpdateType.Dynamic)); receivedUpdateType = null; InputSystem.onAfterUpdate -= callback; InputSystem.Update(); Assert.That(receivedUpdateType, Is.Null); }
public void Events_CanQueueAndReceiveEventsAgainstNonExistingDevices() { // Device IDs are looked up only *after* the system shows the event to us. var receivedCalls = 0; var receivedDeviceId = InputDevice.kInvalidDeviceId; InputSystem.onEvent += eventPtr => { ++receivedCalls; receivedDeviceId = eventPtr.deviceId; }; var inputEvent = DeviceConfigurationEvent.Create(4, 1.0); InputSystem.QueueEvent(ref inputEvent); InputSystem.Update(); Assert.That(receivedCalls, Is.EqualTo(1)); Assert.That(receivedDeviceId, Is.EqualTo(4)); }
public void Controls_SticksProvideAccessToHalfAxes() { var gamepad = InputSystem.AddDevice <Gamepad>(); InputSystem.QueueStateEvent(gamepad, new GamepadState { leftStick = new Vector2(0.5f, 0.5f) }); InputSystem.Update(); Assert.That(gamepad.leftStick.up.ReadValue(), Is.EqualTo(0.5).Within(0.000001)); Assert.That(gamepad.leftStick.down.ReadValue(), Is.EqualTo(0.0).Within(0.000001)); Assert.That(gamepad.leftStick.right.ReadValue(), Is.EqualTo(0.5).Within(0.000001)); Assert.That(gamepad.leftStick.left.ReadValue(), Is.EqualTo(0.0).Within(0.000001)); InputSystem.QueueStateEvent(gamepad, new GamepadState { leftStick = new Vector2(-0.5f, -0.5f) }); InputSystem.Update(); Assert.That(gamepad.leftStick.up.ReadValue(), Is.EqualTo(0.0).Within(0.000001)); Assert.That(gamepad.leftStick.down.ReadValue(), Is.EqualTo(0.5).Within(0.000001)); Assert.That(gamepad.leftStick.right.ReadValue(), Is.EqualTo(0.0).Within(0.000001)); Assert.That(gamepad.leftStick.left.ReadValue(), Is.EqualTo(0.5).Within(0.000001)); }
public void Controls_CanHaveAxisDeadzones() { const string json = @" { ""name"" : ""MyDevice"", ""extend"" : ""Gamepad"", ""controls"" : [ { ""name"" : ""leftTrigger"", ""processors"" : ""axisDeadzone(min=0.1,max=0.9)"" } ] } "; InputSystem.RegisterLayout(json); var device = (Gamepad)InputSystem.AddDevice("MyDevice"); ////NOTE: Unfortunately, this relies on an internal method ATM. var processor = device.leftTrigger.TryGetProcessor <AxisDeadzoneProcessor>(); InputSystem.QueueStateEvent(device, new GamepadState { leftTrigger = 0.05f }); InputSystem.Update(); Assert.That(device.leftTrigger.ReadValue(), Is.Zero.Within(0.0001)); InputSystem.QueueStateEvent(device, new GamepadState { leftTrigger = 0.5f }); InputSystem.Update(); Assert.That(device.leftTrigger.ReadValue(), Is.EqualTo(processor.Process(0.5f, device.leftTrigger))); }
public void Events_CanGetAverageEventLag() { var gamepad = InputSystem.AddDevice <Gamepad>(); var keyboard = InputSystem.AddDevice <Keyboard>(); runtime.advanceTimeEachDynamicUpdate = 0; runtime.currentTime = 10; InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.A), 6); InputSystem.QueueStateEvent(gamepad, new GamepadState { leftStick = new Vector2(0.123f, 0.234f) }, 1); InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.A), 10); InputSystem.Update(); InputSystem.QueueStateEvent(gamepad, new GamepadState { leftStick = new Vector2(0.234f, 0.345f) }, 3); InputSystem.Update(); var metrics = InputSystem.metrics; Assert.That(metrics.averageLagTimePerEvent, Is.EqualTo((9 + 7 + 4 + 0) / 4.0).Within(0.0001)); }
public void Events_CanSwitchToProcessingInFixedUpdates() { var mouse = InputSystem.AddDevice <Mouse>(); var receivedOnChange = true; InputSystem.onSettingsChange += () => receivedOnChange = true; InputSystem.settings.updateMode = InputSettings.UpdateMode.ProcessEventsInFixedUpdate; Assert.That(InputSystem.settings.updateMode, Is.EqualTo(InputSettings.UpdateMode.ProcessEventsInFixedUpdate)); Assert.That(receivedOnChange, Is.True); Assert.That(InputSystem.s_Manager.updateMask & InputUpdateType.Fixed, Is.EqualTo(InputUpdateType.Fixed)); Assert.That(InputSystem.s_Manager.updateMask & InputUpdateType.Dynamic, Is.EqualTo(InputUpdateType.None)); InputSystem.QueueStateEvent(mouse, new MouseState().WithButton(MouseButton.Left)); runtime.currentTimeForFixedUpdate += Time.fixedDeltaTime; InputSystem.Update(InputUpdateType.Fixed); Assert.That(mouse.leftButton.isPressed, Is.True); Assert.That(() => InputSystem.Update(InputUpdateType.Dynamic), Throws.InvalidOperationException); Assert.That(() => InputSystem.Update(InputUpdateType.Manual), Throws.InvalidOperationException); }