Skip to content

Commit aacd1d9

Browse files
author
Rene Damm
committed
MERGE: develop => stable.
2 parents e36044f + 9f2680d commit aacd1d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1685
-568
lines changed

Assets/Samples/EditorWindowDemo.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"displayName": "EditorWindow Demo",
3+
"description": "A simple example of how to use the input system from within EditorWindow code."
4+
}

Assets/Samples/EditorWindowDemo/Editor.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using UnityEditor;
2+
using UnityEngine.InputSystem;
3+
4+
public class EditorWindowDemo : EditorWindow
5+
{
6+
[MenuItem("Window/Input System Editor Window Demo")]
7+
public static void Open()
8+
{
9+
GetWindow<EditorWindowDemo>();
10+
}
11+
12+
protected void OnGUI()
13+
{
14+
// Grab the current pointer device (mouse, pen, touchscreen).
15+
var pointer = Pointer.current;
16+
if (pointer == null)
17+
return;
18+
19+
// Pointer positions should automatically be converted to EditorWindow space of
20+
// the current window. Unlike player window coordinates, this uses UI window space,
21+
// i.e. Y goes top down rather than bottom up.
22+
var position = pointer.position.ReadValue();
23+
var pressure = pointer.pressure.ReadValue();
24+
var contact = pointer.press.isPressed;
25+
26+
EditorGUILayout.LabelField($"Device: {pointer}");
27+
EditorGUILayout.LabelField($"Position: {position}");
28+
EditorGUILayout.LabelField($"Pressure: {pressure}");
29+
EditorGUILayout.LabelField($"Contact?: {contact}");
30+
31+
// Just for kicks, also read out some data from the currently used gamepad (if any).
32+
var gamepad = Gamepad.current;
33+
if (gamepad != null)
34+
{
35+
EditorGUILayout.Space();
36+
EditorGUILayout.LabelField($"Gamepad Left Stick: {gamepad.leftStick.ReadValue()}");
37+
EditorGUILayout.LabelField($"Gamepad Right Stick: {gamepad.leftStick.ReadValue()}");
38+
}
39+
40+
// We want to constantly refresh to show the current values so trigger
41+
// another refresh right away. Otherwise, the values we show will only
42+
// update periodically.
43+
Repaint();
44+
}
45+
}

Assets/Samples/EditorWindowDemo/Editor/EditorWindowDemo.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This is a simple example of how to use the input system in EditorWindow code.
2+
3+
For more details see the [documentation](https://docs.unity3d.com/Packages/com.unity.inputsystem@latest/index.html?subfolder=/manual/UseInEditor.html).

Assets/Samples/EditorWindowDemo/README.md.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Samples/SimpleDemo/SimpleControls.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
using UnityEngine.InputSystem;
77
using UnityEngine.InputSystem.Utilities;
88

9-
public class SimpleControls : IInputActionCollection, IDisposable
9+
public class @SimpleControls: IInputActionCollection, IDisposable
1010
{
1111
private InputActionAsset asset;
12-
public SimpleControls()
12+
public @SimpleControls()
1313
{
1414
asset = InputActionAsset.FromJson(@"{
1515
""name"": ""SimpleControls"",
@@ -207,8 +207,8 @@ public void Disable()
207207
private readonly InputAction m_gameplay_look;
208208
public struct GameplayActions
209209
{
210-
private SimpleControls m_Wrapper;
211-
public GameplayActions(SimpleControls wrapper) { m_Wrapper = wrapper; }
210+
private @SimpleControls m_Wrapper;
211+
public GameplayActions(@SimpleControls wrapper) { m_Wrapper = wrapper; }
212212
public InputAction @fire => m_Wrapper.m_gameplay_fire;
213213
public InputAction @move => m_Wrapper.m_gameplay_move;
214214
public InputAction @look => m_Wrapper.m_gameplay_look;
@@ -221,28 +221,28 @@ public void SetCallbacks(IGameplayActions instance)
221221
{
222222
if (m_Wrapper.m_GameplayActionsCallbackInterface != null)
223223
{
224-
fire.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnFire;
225-
fire.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnFire;
226-
fire.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnFire;
227-
move.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMove;
228-
move.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMove;
229-
move.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMove;
230-
look.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnLook;
231-
look.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnLook;
232-
look.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnLook;
224+
@fire.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnFire;
225+
@fire.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnFire;
226+
@fire.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnFire;
227+
@move.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMove;
228+
@move.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMove;
229+
@move.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMove;
230+
@look.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnLook;
231+
@look.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnLook;
232+
@look.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnLook;
233233
}
234234
m_Wrapper.m_GameplayActionsCallbackInterface = instance;
235235
if (instance != null)
236236
{
237-
fire.started += instance.OnFire;
238-
fire.performed += instance.OnFire;
239-
fire.canceled += instance.OnFire;
240-
move.started += instance.OnMove;
241-
move.performed += instance.OnMove;
242-
move.canceled += instance.OnMove;
243-
look.started += instance.OnLook;
244-
look.performed += instance.OnLook;
245-
look.canceled += instance.OnLook;
237+
@fire.started += instance.OnFire;
238+
@fire.performed += instance.OnFire;
239+
@fire.canceled += instance.OnFire;
240+
@move.started += instance.OnMove;
241+
@move.performed += instance.OnMove;
242+
@move.canceled += instance.OnMove;
243+
@look.started += instance.OnLook;
244+
@look.performed += instance.OnLook;
245+
@look.canceled += instance.OnLook;
246246
}
247247
}
248248
}

Assets/Tests/InputSystem/CoreTests_Actions.cs

Lines changed: 109 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3723,6 +3723,36 @@ public void Actions_CanLookUpActionInAssetByName()
37233723
}, Is.Not.AllocatingGCMemory());
37243724
}
37253725

3726+
[Test]
3727+
[Category("Actions")]
3728+
public void Actions_CanRemoveActionFromMap()
3729+
{
3730+
var asset = ScriptableObject.CreateInstance<InputActionAsset>();
3731+
3732+
var map = new InputActionMap("test");
3733+
asset.AddActionMap(map);
3734+
3735+
var action1 = map.AddAction("action1", binding: "<Gamepad>/buttonSouth");
3736+
var action2 = map.AddAction("action2", binding: "<Gamepad>/buttonNorth");
3737+
var action3 = map.AddAction("action3", binding: "<Gamepad>/buttonWest");
3738+
3739+
asset.RemoveAction("action2");
3740+
3741+
Assert.That(action2.actionMap, Is.Null);
3742+
Assert.That(asset.FindAction("action2"), Is.Null);
3743+
Assert.That(map.actions, Has.Count.EqualTo(2));
3744+
Assert.That(map.actions, Has.Exactly(1).SameAs(action1));
3745+
Assert.That(map.actions, Has.Exactly(1).SameAs(action3));
3746+
Assert.That(action1.bindings, Is.EquivalentTo(new[] {new InputBinding("<Gamepad>/buttonSouth", action: "action1")}));
3747+
Assert.That(action2.bindings, Is.EquivalentTo(new[] {new InputBinding("<Gamepad>/buttonNorth", action: "action2")}));
3748+
Assert.That(action3.bindings, Is.EquivalentTo(new[] {new InputBinding("<Gamepad>/buttonWest", action: "action3")}));
3749+
Assert.That(map.bindings, Is.EquivalentTo(new[]
3750+
{
3751+
new InputBinding("<Gamepad>/buttonSouth", action: "action1"),
3752+
new InputBinding("<Gamepad>/buttonWest", action: "action3")
3753+
}));
3754+
}
3755+
37263756
[Test]
37273757
[Category("Actions")]
37283758
public void Actions_CanRemoveActionMapFromAsset()
@@ -4132,8 +4162,9 @@ public void Actions_CanMaskOutBindingsByBindingGroup_OnAction()
41324162

41334163
action.bindingMask = new InputBinding {groups = "gamepad"};
41344164

4135-
Assert.That(action.controls, Has.Count.EqualTo(1));
4165+
Assert.That(action.controls, Has.Count.EqualTo(2));
41364166
Assert.That(action.controls, Has.Exactly(1).SameAs(gamepad.buttonSouth));
4167+
Assert.That(action.controls, Has.Exactly(1).SameAs(mouse.leftButton));
41374168
Assert.That(action.bindingMask, Is.EqualTo(new InputBinding {groups = "gamepad"}));
41384169

41394170
action.bindingMask = null;
@@ -4206,8 +4237,9 @@ public void Actions_CanMaskOutBindingsByBindingGroup_OnActionMap()
42064237
map.bindingMask = new InputBinding {groups = "gamepad"};
42074238

42084239
Assert.That(action1.controls, Has.Count.EqualTo(1));
4209-
Assert.That(action2.controls, Has.Count.Zero);
42104240
Assert.That(action1.controls, Has.Exactly(1).SameAs(gamepad.buttonSouth));
4241+
Assert.That(action2.controls, Has.Count.EqualTo(1));
4242+
Assert.That(action2.controls, Has.Exactly(1).SameAs(mouse.leftButton));
42114243
}
42124244

42134245
[Test]
@@ -4254,6 +4286,26 @@ public void Actions_CanMaskOutBindingsByBindingGroup_OnAsset()
42544286
Assert.That(action2.controls, Has.Exactly(1).SameAs(keyboard.bKey));
42554287
}
42564288

4289+
[Test]
4290+
[Category("Actions")]
4291+
public void Actions_WhenMaskingByGroup_BindingsNotInAnyGroupWillBeActive()
4292+
{
4293+
var gamepad = InputSystem.AddDevice<Gamepad>();
4294+
var mouse = InputSystem.AddDevice<Mouse>();
4295+
InputSystem.AddDevice<Keyboard>();
4296+
4297+
var action = new InputAction();
4298+
action.AddBinding("<Gamepad>/buttonSouth", groups: "Gamepad");
4299+
action.AddBinding("<Keyboard>/space", groups: "Keyboard&Mouse");
4300+
action.AddBinding("<Pointer>/press");
4301+
4302+
action.bindingMask = InputBinding.MaskByGroup("Gamepad");
4303+
4304+
Assert.That(action.controls, Has.Count.EqualTo(2));
4305+
Assert.That(action.controls, Has.Exactly(1).SameAs(gamepad.buttonSouth));
4306+
Assert.That(action.controls, Has.Exactly(1).SameAs(mouse.press));
4307+
}
4308+
42574309
// When we have an .inputactions asset, at runtime we should end up with a single array of resolved
42584310
// controls, single array of trigger states, and so on. The expectation is that users won't generally
42594311
// go and configure each map in an asset in a wildly different way. Rather, the maps will usually perform
@@ -4387,6 +4439,54 @@ public void Actions_CanHaveParametersOnComposites()
43874439
Is.EqualTo(CompositeWithParameters.EnumParameter.B));
43884440
}
43894441

4442+
[Test]
4443+
[Category("Actions")]
4444+
[TestCase("", "<Gamepad>/buttonSouth", "<Gamepad>/buttonWest", "<Gamepad>/buttonEast")]
4445+
[TestCase("<Gamepad>/buttonNorth", "", "<Gamepad>/buttonWest", "<Gamepad>/buttonEast")]
4446+
[TestCase("<Gamepad>/buttonNorth", "<Gamepad>/buttonSouth", "", "<Gamepad>/buttonEast")]
4447+
[TestCase("<Gamepad>/buttonNorth", "<Gamepad>/buttonSouth", "<Gamepad>/buttonWest", "")]
4448+
public void Actions_CanHaveCompositesWithPartsThatAreNotBound(string up, string down, string left, string right)
4449+
{
4450+
var gamepad = InputSystem.AddDevice<Gamepad>();
4451+
4452+
var action = new InputAction();
4453+
action.AddCompositeBinding("2DVector")
4454+
.With("Up", up)
4455+
.With("Down", down)
4456+
.With("Left", left)
4457+
.With("Right", right);
4458+
4459+
action.Enable();
4460+
4461+
if (!string.IsNullOrEmpty(up))
4462+
{
4463+
Press(gamepad.buttonNorth);
4464+
Assert.That(action.ReadValue<Vector2>(), Is.EqualTo(Vector2.up).Using(Vector2EqualityComparer.Instance));
4465+
Release(gamepad.buttonNorth);
4466+
}
4467+
4468+
if (!string.IsNullOrEmpty(down))
4469+
{
4470+
Press(gamepad.buttonSouth);
4471+
Assert.That(action.ReadValue<Vector2>(), Is.EqualTo(Vector2.down).Using(Vector2EqualityComparer.Instance));
4472+
Release(gamepad.buttonSouth);
4473+
}
4474+
4475+
if (!string.IsNullOrEmpty(left))
4476+
{
4477+
Press(gamepad.buttonWest);
4478+
Assert.That(action.ReadValue<Vector2>(), Is.EqualTo(Vector2.left).Using(Vector2EqualityComparer.Instance));
4479+
Release(gamepad.buttonWest);
4480+
}
4481+
4482+
if (!string.IsNullOrEmpty(right))
4483+
{
4484+
Press(gamepad.buttonEast);
4485+
Assert.That(action.ReadValue<Vector2>(), Is.EqualTo(Vector2.right).Using(Vector2EqualityComparer.Instance));
4486+
Release(gamepad.buttonEast);
4487+
}
4488+
}
4489+
43904490
[Test]
43914491
[Category("Actions")]
43924492
[Ignore("TODO")]
@@ -5497,9 +5597,9 @@ public void Actions_ApplyingNullOverride_IsSameAsRemovingOverride()
54975597
public void Actions_ApplyingEmptyStringOverride_IsSameAsDisablingBinding()
54985598
{
54995599
var gamepad = InputSystem.AddDevice<Gamepad>();
5500-
var action = new InputAction(binding: "/gamepad/leftTrigger");
5600+
var action = new InputAction(binding: "<Gamepad>/leftTrigger");
55015601

5502-
bool performed = false;
5602+
var performed = false;
55035603
action.performed += _ => performed = true;
55045604

55055605
action.Enable();
@@ -5516,6 +5616,11 @@ public void Actions_ApplyingEmptyStringOverride_IsSameAsDisablingBinding()
55165616
Press(gamepad.leftTrigger);
55175617

55185618
Assert.That(performed, Is.False);
5619+
5620+
// We had a bug (case 1187163) where InputActionState would cause an exception by not
5621+
// respecting the empty path when checking if a newly added device is affecting the state.
5622+
// Just add a device here to make sure that's handled correctly.
5623+
Assert.That(() => InputSystem.AddDevice<Gamepad>(), Throws.Nothing);
55195624
}
55205625

55215626
[Test]

0 commit comments

Comments
 (0)