Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions Assets/Tests/InputSystem/CoreTests_Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3164,14 +3164,14 @@ public void Actions_CanQueryMagnitudeFromAction_WithAxisControl(InputActionType
Assert.That(action.activeControl, Is.Null);
Assert.That(action.phase, Is.EqualTo(InputActionPhase.Disabled));
Assert.That(action.ReadValue<float>(), Is.EqualTo(0f));
Assert.That(action.GetMagnitude(), Is.EqualTo(0f));
Assert.That(action.GetControlMagnitude(), Is.EqualTo(0f));

action.Enable();

Assert.That(action.activeControl, Is.Null);
Assert.That(action.phase, Is.EqualTo(InputActionPhase.Waiting));
Assert.That(action.ReadValue<float>(), Is.EqualTo(0f));
Assert.That(action.GetMagnitude(), Is.EqualTo(0f));
Assert.That(action.GetControlMagnitude(), Is.EqualTo(0f));

Set(gamepad.leftTrigger, 0.123f);

Expand All @@ -3181,14 +3181,14 @@ public void Actions_CanQueryMagnitudeFromAction_WithAxisControl(InputActionType
Assert.That(action.activeControl, Is.SameAs(gamepad.leftTrigger));
Assert.That(action.phase, Is.EqualTo(InputActionPhase.Started));
Assert.That(action.ReadValue<float>(), Is.EqualTo(expectedValue).Within(0.00001));
Assert.That(action.GetMagnitude(), Is.EqualTo(0.123f).Within(0.00001));
Assert.That(action.GetControlMagnitude(), Is.EqualTo(0.123f).Within(0.00001));

Set(gamepad.leftTrigger, 0f);

Assert.That(action.activeControl, Is.Null);
Assert.That(action.phase, Is.EqualTo(InputActionPhase.Waiting));
Assert.That(action.ReadValue<float>(), Is.EqualTo(0f));
Assert.That(action.GetMagnitude(), Is.EqualTo(0f));
Assert.That(action.GetControlMagnitude(), Is.EqualTo(0f));
}

[Test]
Expand All @@ -3202,14 +3202,14 @@ public void Actions_CanQueryMagnitudeFromAction_WithStickControl()
Assert.That(action.activeControl, Is.Null);
Assert.That(action.phase, Is.EqualTo(InputActionPhase.Disabled));
Assert.That(action.ReadValue<Vector2>(), Is.EqualTo(Vector2.zero));
Assert.That(action.GetMagnitude(), Is.EqualTo(0f));
Assert.That(action.GetControlMagnitude(), Is.EqualTo(0f));

action.Enable();

Assert.That(action.activeControl, Is.Null);
Assert.That(action.phase, Is.EqualTo(InputActionPhase.Waiting));
Assert.That(action.ReadValue<Vector2>(), Is.EqualTo(Vector2.zero));
Assert.That(action.GetMagnitude(), Is.EqualTo(0f));
Assert.That(action.GetControlMagnitude(), Is.EqualTo(0f));

Set(gamepad.leftStick, new Vector2(0.123f, 0.234f));

Expand All @@ -3218,14 +3218,14 @@ public void Actions_CanQueryMagnitudeFromAction_WithStickControl()
Assert.That(action.activeControl, Is.SameAs(gamepad.leftStick));
Assert.That(action.phase, Is.EqualTo(InputActionPhase.Started));
Assert.That(action.ReadValue<Vector2>(), Is.EqualTo(expectedValue).Using(Vector2EqualityComparer.Instance));
Assert.That(action.GetMagnitude(), Is.EqualTo(expectedValue.magnitude));
Assert.That(action.GetControlMagnitude(), Is.EqualTo(expectedValue.magnitude));

Set(gamepad.leftStick, Vector2.zero);

Assert.That(action.activeControl, Is.Null);
Assert.That(action.phase, Is.EqualTo(InputActionPhase.Waiting));
Assert.That(action.ReadValue<Vector2>(), Is.EqualTo(Vector2.zero));
Assert.That(action.GetMagnitude(), Is.EqualTo(0f));
Assert.That(action.GetControlMagnitude(), Is.EqualTo(0f));
}

[Test]
Expand All @@ -3247,14 +3247,14 @@ public void Actions_CanQueryMagnitudeFromAction_WithCompositeAxisControl(InputAc
Assert.That(action.activeControl, Is.Null);
Assert.That(action.phase, Is.EqualTo(InputActionPhase.Disabled));
Assert.That(action.ReadValue<float>(), Is.EqualTo(0f));
Assert.That(action.GetMagnitude(), Is.EqualTo(0f));
Assert.That(action.GetControlMagnitude(), Is.EqualTo(0f));

action.Enable();

Assert.That(action.activeControl, Is.Null);
Assert.That(action.phase, Is.EqualTo(InputActionPhase.Waiting));
Assert.That(action.ReadValue<float>(), Is.EqualTo(0f));
Assert.That(action.GetMagnitude(), Is.EqualTo(0f));
Assert.That(action.GetControlMagnitude(), Is.EqualTo(0f));

Press(keyboard.dKey);

Expand All @@ -3264,22 +3264,22 @@ public void Actions_CanQueryMagnitudeFromAction_WithCompositeAxisControl(InputAc
Assert.That(action.activeControl, Is.SameAs(keyboard.dKey));
Assert.That(action.phase, Is.EqualTo(InputActionPhase.Started));
Assert.That(action.ReadValue<float>(), Is.EqualTo(expectedValue).Within(0.00001));
Assert.That(action.GetMagnitude(), Is.EqualTo(1f).Within(0.00001));
Assert.That(action.GetControlMagnitude(), Is.EqualTo(1f).Within(0.00001));

Release(keyboard.dKey);
Press(keyboard.aKey);

Assert.That(action.activeControl, Is.SameAs(keyboard.aKey));
Assert.That(action.phase, Is.EqualTo(InputActionPhase.Started));
Assert.That(action.ReadValue<float>(), Is.EqualTo(-expectedValue).Within(0.00001));
Assert.That(action.GetMagnitude(), Is.EqualTo(1f).Within(0.00001));
Assert.That(action.GetControlMagnitude(), Is.EqualTo(1f).Within(0.00001));

Release(keyboard.aKey);

Assert.That(action.activeControl, Is.Null);
Assert.That(action.phase, Is.EqualTo(InputActionPhase.Waiting));
Assert.That(action.ReadValue<float>(), Is.EqualTo(0f));
Assert.That(action.GetMagnitude(), Is.EqualTo(0f));
Assert.That(action.GetControlMagnitude(), Is.EqualTo(0f));
}

[Test]
Expand All @@ -3303,14 +3303,14 @@ public void Actions_CanQueryMagnitudeFromAction_WithComposite2DVectorControl(Inp
Assert.That(action.activeControl, Is.Null);
Assert.That(action.phase, Is.EqualTo(InputActionPhase.Disabled));
Assert.That(action.ReadValue<Vector2>(), Is.EqualTo(Vector2.zero));
Assert.That(action.GetMagnitude(), Is.EqualTo(0f));
Assert.That(action.GetControlMagnitude(), Is.EqualTo(0f));

action.Enable();

Assert.That(action.activeControl, Is.Null);
Assert.That(action.phase, Is.EqualTo(InputActionPhase.Waiting));
Assert.That(action.ReadValue<Vector2>(), Is.EqualTo(Vector2.zero));
Assert.That(action.GetMagnitude(), Is.EqualTo(0f));
Assert.That(action.GetControlMagnitude(), Is.EqualTo(0f));

Press(keyboard.sKey);

Expand All @@ -3320,7 +3320,7 @@ public void Actions_CanQueryMagnitudeFromAction_WithComposite2DVectorControl(Inp
Assert.That(action.activeControl, Is.SameAs(keyboard.sKey));
Assert.That(action.phase, Is.EqualTo(InputActionPhase.Started));
Assert.That(action.ReadValue<Vector2>(), Is.EqualTo(expectedValue).Using(Vector2EqualityComparer.Instance));
Assert.That(action.GetMagnitude(), Is.EqualTo(1f).Within(0.00001));
Assert.That(action.GetControlMagnitude(), Is.EqualTo(1f).Within(0.00001));

Press(keyboard.dKey);

Expand All @@ -3329,15 +3329,15 @@ public void Actions_CanQueryMagnitudeFromAction_WithComposite2DVectorControl(Inp
Assert.That(action.activeControl, Is.SameAs(keyboard.dKey));
Assert.That(action.phase, Is.EqualTo(InputActionPhase.Started));
Assert.That(action.ReadValue<Vector2>(), Is.EqualTo(expectedValue).Using(Vector2EqualityComparer.Instance));
Assert.That(action.GetMagnitude(), Is.EqualTo(new Vector2(1f, -1f).magnitude).Within(0.00001));
Assert.That(action.GetControlMagnitude(), Is.EqualTo(new Vector2(1f, -1f).magnitude).Within(0.00001));

Release(keyboard.dKey);
Release(keyboard.sKey);

Assert.That(action.activeControl, Is.Null);
Assert.That(action.phase, Is.EqualTo(InputActionPhase.Waiting));
Assert.That(action.ReadValue<Vector2>(), Is.EqualTo(Vector2.zero));
Assert.That(action.GetMagnitude(), Is.EqualTo(0f));
Assert.That(action.GetControlMagnitude(), Is.EqualTo(0f));
}

[Test]
Expand All @@ -3356,35 +3356,35 @@ public void Actions_CanQueryMagnitudeFromAction_WithQuaternionControl_ReturnsInv
Assert.That(action.activeControl, Is.Null);
Assert.That(action.phase, Is.EqualTo(InputActionPhase.Disabled));
Assert.That(action.ReadValue<Quaternion>(), Is.EqualTo(default(Quaternion)));
Assert.That(action.GetMagnitude(), Is.EqualTo(0f));
Assert.That(action.GetControlMagnitude(), Is.EqualTo(0f));

action.Enable();

Assert.That(action.activeControl, Is.Null);
Assert.That(action.phase, Is.EqualTo(InputActionPhase.Waiting));
Assert.That(action.ReadValue<Quaternion>(), Is.EqualTo(default(Quaternion)));
Assert.That(action.GetMagnitude(), Is.EqualTo(0f));
Assert.That(action.GetControlMagnitude(), Is.EqualTo(0f));

Set(sensor.attitude, Quaternion.Euler(30f, 60f, 45f));

Assert.That(action.activeControl, Is.SameAs(sensor.attitude));
Assert.That(action.phase, Is.EqualTo(InputActionPhase.Started));
Assert.That(action.ReadValue<Quaternion>(), Is.EqualTo(Quaternion.Euler(30f, 60f, 45f)).Using(QuaternionEqualityComparer.Instance));
Assert.That(action.GetMagnitude(), Is.EqualTo(-1f));
Assert.That(action.GetControlMagnitude(), Is.EqualTo(-1f));

Set(sensor.attitude, Quaternion.identity);

Assert.That(action.activeControl, Is.SameAs(sensor.attitude));
Assert.That(action.phase, Is.EqualTo(InputActionPhase.Started));
Assert.That(action.ReadValue<Quaternion>(), Is.EqualTo(Quaternion.identity));
Assert.That(action.GetMagnitude(), Is.EqualTo(-1f));
Assert.That(action.GetControlMagnitude(), Is.EqualTo(-1f));

Set(sensor.attitude, default(Quaternion));

Assert.That(action.activeControl, Is.Null);
Assert.That(action.phase, Is.EqualTo(InputActionPhase.Waiting));
Assert.That(action.ReadValue<Quaternion>(), Is.EqualTo(default(Quaternion)));
Assert.That(action.GetMagnitude(), Is.EqualTo(0f));
Assert.That(action.GetControlMagnitude(), Is.EqualTo(0f));
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ however, it has to be formatted properly to pass verification tests.
### Added
- Added new methods and properties to [`InputAction`](xref:UnityEngine.InputSystem.InputAction):
- [`InputAction.activeValueType`](xref:UnityEngine.InputSystem.InputAction.activeValueType) returns the `Type` expected by `ReadValue<TValue>` based on the currently active control that is driving the action.
- [`InputAction.GetMagnitude`](xref:UnityEngine.InputSystem.InputAction.GetMagnitude) returns the current amount of actuation of the control that is driving the action.
- [`InputAction.GetControlMagnitude`](xref:UnityEngine.InputSystem.InputAction.GetControlMagnitude) returns the current amount of actuation of the control that is driving the action.
- [`InputAction.WasCompletedThisFrame`](xref:UnityEngine.InputSystem.InputAction.WasCompletedThisFrame) returns `true` on the frame that the action stopped being in the performed phase. This allows for similar functionality to [`WasPressedThisFrame`](xref:UnityEngine.InputSystem.InputAction.WasPressedThisFrame)/[`WasReleasedThisFrame`](xref:UnityEngine.InputSystem.InputAction.WasReleasedThisFrame) when paired with [`WasPerformedThisFrame`](xref:UnityEngine.InputSystem.InputAction.WasPerformedThisFrame) except it is directly based on the interactions driving the action. For example, you can use it to distinguish between the button being released or whether it was released after being held for long enough to perform when using the Hold interaction.
- Added Copy, Paste and Cut support for Action Maps, Actions and Bindings via context menu and key command shortcuts.
- Added Dual Sense Edge controller to be mapped to the same layout as the Dual Sense controller
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,7 @@ public unsafe object ReadValueAsObject()
/// </remarks>
/// <seealso cref="InputControl.EvaluateMagnitude()"/>
/// <seealso cref="InputBindingComposite.EvaluateMagnitude"/>
public unsafe float GetMagnitude()
public unsafe float GetControlMagnitude()
{
var state = GetOrCreateActionMap().m_State;
if (state != null)
Expand Down