Skip to content

Commit 931fa48

Browse files
authored
Merge branch 'develop' into throw-error-nda-inputsystem-without-plugin
2 parents e7f7b63 + 58bd3ec commit 931fa48

File tree

10 files changed

+184
-35
lines changed

10 files changed

+184
-35
lines changed

Assets/Tests/InputSystem/Plugins/OnScreenTests.cs

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ public void Devices_DisablingLastOnScreenControlDoesReportActiveControl()
395395
// https://fogbugz.unity3d.com/f/cases/1271942
396396
[UnityTest]
397397
[Category("Devices")]
398-
public IEnumerator Devices_CanHaveOnScreenJoystickControls()
398+
public IEnumerator Devices_CanHaveOnScreenJoystickControls([Values(false, true)] bool useInIsolation)
399399
{
400400
foreach (var c in Camera.allCameras)
401401
Object.Destroy(c.gameObject);
@@ -422,18 +422,33 @@ public IEnumerator Devices_CanHaveOnScreenJoystickControls()
422422
canvasGO.AddComponent<GraphicRaycaster>();
423423
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
424424

425-
var stickGO = new GameObject("Stick");
426-
stickGO.SetActive(false);
427-
var stickTransform = stickGO.AddComponent<RectTransform>();
428-
var stick = stickGO.AddComponent<OnScreenStick>();
429-
stickGO.AddComponent<Image>();
430-
stickTransform.SetParent(canvasTransform);
431-
stickTransform.anchorMin = new Vector2(0, 0);
432-
stickTransform.anchorMax = new Vector2(0, 0);
433-
stickTransform.anchoredPosition = new Vector2(100, 100);
434-
stickTransform.sizeDelta = new Vector2(100, 100);
435-
stick.controlPath = "<Gamepad>/leftStick";
436-
stickGO.SetActive(true);
425+
var stickLeftGO = new GameObject("StickLeft");
426+
stickLeftGO.SetActive(false);
427+
var stickLeftTransform = stickLeftGO.AddComponent<RectTransform>();
428+
var stickLeft = stickLeftGO.AddComponent<OnScreenStick>();
429+
stickLeft.useIsolatedInputActions = useInIsolation;
430+
stickLeftGO.AddComponent<Image>();
431+
stickLeftTransform.SetParent(canvasTransform);
432+
stickLeftTransform.anchorMin = new Vector2(0, 0);
433+
stickLeftTransform.anchorMax = new Vector2(0, 0);
434+
stickLeftTransform.anchoredPosition = new Vector2(100, 100);
435+
stickLeftTransform.sizeDelta = new Vector2(100, 100);
436+
stickLeft.controlPath = "<Gamepad>/leftStick";
437+
stickLeftGO.SetActive(true);
438+
439+
var stickRightGO = new GameObject("StickRight");
440+
stickRightGO.SetActive(false);
441+
var stickRightTransform = stickRightGO.AddComponent<RectTransform>();
442+
var stickRight = stickRightGO.AddComponent<OnScreenStick>();
443+
stickRight.useIsolatedInputActions = useInIsolation;
444+
stickRightGO.AddComponent<Image>();
445+
stickRightTransform.SetParent(canvasTransform);
446+
stickRightTransform.anchorMin = new Vector2(0, 0);
447+
stickRightTransform.anchorMax = new Vector2(0, 0);
448+
stickRightTransform.anchoredPosition = new Vector2(500, 100);
449+
stickRightTransform.sizeDelta = new Vector2(100, 100);
450+
stickRight.controlPath = "<Gamepad>/rightStick";
451+
stickRightGO.SetActive(true);
437452

438453
var buttonGO = new GameObject("Button");
439454
buttonGO.SetActive(false);
@@ -464,7 +479,7 @@ public IEnumerator Devices_CanHaveOnScreenJoystickControls()
464479

465480
Assert.That(player.devices, Is.EquivalentTo(new[] { Gamepad.all[0] }));
466481

467-
// Touch the stick and drag it upwards.
482+
// Touch the Left stick and drag it upwards.
468483
BeginTouch(1, new Vector2(150, 150));
469484
yield return null;
470485
eventSystem.Update();
@@ -491,6 +506,38 @@ public IEnumerator Devices_CanHaveOnScreenJoystickControls()
491506
InputSystem.Update(); // Button is feeding events when responding to UI events.
492507

493508
Assert.That(Gamepad.all[0].buttonSouth.isPressed, Is.False);
509+
510+
// Touch the right stick and drag it downwards
511+
BeginTouch(2, new Vector2(550, 150));
512+
yield return null;
513+
eventSystem.Update();
514+
Assert.That(eventSystem.IsPointerOverGameObject(), Is.True);
515+
MoveTouch(2, new Vector2(550, 50));
516+
yield return null;
517+
eventSystem.Update();
518+
InputSystem.Update(); // Stick is feeding events when responding to UI events.
519+
520+
Assert.That(Gamepad.all[0].leftStick.ReadValue(), Is.EqualTo(new Vector2(0, 1)).Using(Vector2EqualityComparer.Instance));
521+
Assert.That(Gamepad.all[0].rightStick.ReadValue(), Is.EqualTo(new Vector2(0, -1)).Using(Vector2EqualityComparer.Instance));
522+
523+
// Release finger one and move second and ensure that it still works
524+
EndTouch(1, new Vector2(550, 200));
525+
MoveTouch(2, new Vector2(600, 150));
526+
yield return null;
527+
eventSystem.Update();
528+
InputSystem.Update(); // Stick is feeding events when responding to UI events.
529+
530+
Assert.That(Gamepad.all[0].leftStick.ReadValue(), Is.EqualTo(new Vector2(0, 0)).Using(Vector2EqualityComparer.Instance));
531+
Assert.That(Gamepad.all[0].rightStick.ReadValue(), Is.EqualTo(new Vector2(1, 0)).Using(Vector2EqualityComparer.Instance));
532+
533+
// Release finger two
534+
EndTouch(2, new Vector2(600, 150));
535+
yield return null;
536+
eventSystem.Update();
537+
InputSystem.Update(); // Stick is feeding events when responding to UI events.
538+
539+
Assert.That(Gamepad.all[0].leftStick.ReadValue(), Is.EqualTo(new Vector2(0, 0)).Using(Vector2EqualityComparer.Instance));
540+
Assert.That(Gamepad.all[0].rightStick.ReadValue(), Is.EqualTo(new Vector2(0, 0)).Using(Vector2EqualityComparer.Instance));
494541
}
495542

496543
[UnityTest]
@@ -519,6 +566,9 @@ public IEnumerator Devices_OnScreenStickDoesNotReceivePointerUpEventsInIsolatedM
519566
uiTestScene.uiInputModule.actionsAsset.actionMaps[0].LazyResolveBindings(true);
520567
};
521568

569+
// Ensure that the OnScreenStick component has been started
570+
yield return null;
571+
522572
yield return uiTestScene.PressAndDrag(image, new Vector2(50, 50));
523573

524574
// The OnScreenStick when being driven from the UI (non-isolated mode) queues the events into the next

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@ however, it has to be formatted properly to pass verification tests.
3434
- Fixed an issue with default device selection when adding new Control Scheme.
3535
- Fixed an issue where action map delegates were not updated when the asset already assigned to the PlayerInput component were changed [ISXB-711](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-711).
3636
- Fixed Action properties edition in the UI Toolkit version of the Input Actions Asset editor. [ISXB-1277](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1277)
37+
- Fixed an editor crash caused by input debugger device state window reusing cached state when reconnecting Stadia controller. [ISXB-658](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-658)
3738
- Fixed an issue where batch jobs would fail with "Error: Error building Player because scripts are compiling" if a source generated .inputactions asset is out of sync with its generated source code (ISXB-1300).
39+
- Fixed multiple `OnScreenStick` Components that does not work together when using them simultaneously in isolation mode. [ISXB-813](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-813)
40+
- Fixed an issue in input actions editor window that caused certain fields in custom input composite bindings to require multiple clicks to action / focus. [ISXB-1171](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1171)
3841

3942
### Changed
43+
- Changed location of the link xml file (code stripping rules), from a temporary directory to the project Library folder (ISX-2140).
4044
- Added back the InputManager to InputSystem project-wide asset migration code with performance improvement (ISX-2086).
4145
- Changed `OnScreenControl` to automaticaly switch, in Single Player with autoswitch enabled, to the target device control scheme when the first component is enabled to prevent bad interactions when it start.
4246
- Changed paremeter `overrideModifiersNeedToBePressedFirst` to obsolete for `ButtonWithOneModifier`, `ButtonWithTwoModifiers`, `OneModifierComposite` and `TwoModifiersComposite` in favour the new `modifiersOrder` parameter which is more explicit.

Packages/com.unity.inputsystem/InputSystem/Editor/BuildPipeline/LinkFileGenerator.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,12 @@ public string GenerateAdditionalLinkXmlFile(BuildReport report, UnityLinkerBuild
7777

7878
sb.AppendLine("</linker>");
7979

80-
var filePathName = Path.Combine(Application.dataPath, "..", "Temp", "InputSystemLink.xml");
81-
File.WriteAllText(filePathName, sb.ToString());
82-
return filePathName;
80+
var linkXmlDirectory = Path.Combine(Application.dataPath, "..", "Library", "InputSystem");
81+
var linkXmlFile = Path.Combine(linkXmlDirectory, $"{data.target}Link.xml");
82+
83+
Directory.CreateDirectory(linkXmlDirectory);
84+
File.WriteAllText(linkXmlFile, sb.ToString());
85+
return linkXmlFile;
8386
}
8487

8588
static bool IsTypeUsedViaReflectionByInputSystem(Type type)

Packages/com.unity.inputsystem/InputSystem/Editor/Internal/InputStateWindow.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,26 @@ public unsafe void InitializeWithControl(InputControl control)
113113
PollBuffersFromControl(control, selectBuffer: true);
114114

115115
titleContent = new GUIContent(control.displayName);
116+
117+
InputSystem.onDeviceChange += OnDeviceChange;
118+
}
119+
120+
private void OnDeviceChange(InputDevice device, InputDeviceChange change)
121+
{
122+
if (m_Control is null)
123+
return;
124+
125+
if (device.deviceId != m_Control.device.deviceId)
126+
return;
127+
128+
if (change == InputDeviceChange.Removed)
129+
Close();
130+
}
131+
132+
internal void OnDestroy()
133+
{
134+
if (m_Control != null)
135+
InputSystem.onDeviceChange -= OnDeviceChange;
116136
}
117137

118138
private unsafe void PollBuffersFromControl(InputControl control, bool selectBuffer = false)
@@ -286,6 +306,12 @@ private string FormatByte(byte value)
286306
////TODO: support dumping multiple state side-by-side when comparing
287307
private void DrawHexDump()
288308
{
309+
if (m_StateBuffers is null)
310+
return;
311+
312+
if (m_StateBuffers[m_SelectedStateBuffer] is null)
313+
return;
314+
289315
m_HexDumpScrollPosition = EditorGUILayout.BeginScrollView(m_HexDumpScrollPosition);
290316

291317
var stateBuffer = m_StateBuffers[m_SelectedStateBuffer];

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorSettingsProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ private void OnFocusOut(FocusOutEvent @event = null)
176176
DelayFocusLost(element == null);
177177
}
178178

179-
private void OnStateChanged(InputActionsEditorState newState)
179+
private void OnStateChanged(InputActionsEditorState newState, UIRebuildMode editorRebuildMode)
180180
{
181181
#if UNITY_INPUT_SYSTEM_INPUT_ACTIONS_EDITOR_AUTO_SAVE_ON_FOCUS_LOST
182182
// No action, auto-saved on edit-focus lost

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ private void BuildUI()
237237
m_StateContainer.Initialize(rootVisualElement.Q("action-editor"));
238238
}
239239

240-
private void OnStateChanged(InputActionsEditorState newState)
240+
private void OnStateChanged(InputActionsEditorState newState, UIRebuildMode editorRebuildMode)
241241
{
242242
DirtyInputActionsEditorWindow(newState);
243243
m_State = newState;

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/StateContainer.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@
77

88
namespace UnityEngine.InputSystem.Editor
99
{
10+
// Enum used to dictate if a state change should rebuild the Input Actions editor UI
11+
internal enum UIRebuildMode
12+
{
13+
None,
14+
Rebuild,
15+
}
16+
1017
internal class StateContainer
1118
{
12-
public event Action<InputActionsEditorState> StateChanged;
19+
public event Action<InputActionsEditorState, UIRebuildMode> StateChanged;
1320

1421
private VisualElement m_RootVisualElement;
1522
private InputActionsEditorState m_State;
@@ -21,7 +28,7 @@ public StateContainer(InputActionsEditorState initialState, string assetGUID)
2128
this.assetGUID = assetGUID;
2229
}
2330

24-
public void Dispatch(Command command)
31+
public void Dispatch(Command command, UIRebuildMode editorRebuildMode = UIRebuildMode.Rebuild)
2532
{
2633
if (command == null)
2734
throw new ArgumentNullException(nameof(command));
@@ -36,7 +43,7 @@ public void Dispatch(Command command)
3643
// catch exceptions here or the UIToolkit scheduled event will keep firing forever.
3744
try
3845
{
39-
StateChanged?.Invoke(m_State);
46+
StateChanged?.Invoke(m_State, editorRebuildMode);
4047
}
4148
catch (Exception e)
4249
{
@@ -55,9 +62,9 @@ public void Initialize(VisualElement rootVisualElement)
5562
m_RootVisualElement.Unbind();
5663
m_RootVisualElement.TrackSerializedObjectValue(m_State.serializedObject, so =>
5764
{
58-
StateChanged?.Invoke(m_State);
65+
StateChanged?.Invoke(m_State, UIRebuildMode.Rebuild);
5966
});
60-
StateChanged?.Invoke(m_State);
67+
StateChanged?.Invoke(m_State, UIRebuildMode.Rebuild);
6168
rootVisualElement.Bind(m_State.serializedObject);
6269
}
6370

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/CompositeBindingPropertiesView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public override void RedrawUI(ViewState viewState)
4242

4343
viewState.parameterListView.onChange = () =>
4444
{
45-
Dispatch(Commands.UpdatePathNameAndValues(viewState.parameterListView.GetParameters(), viewState.selectedBindingPath));
45+
Dispatch(Commands.UpdatePathNameAndValues(viewState.parameterListView.GetParameters(), viewState.selectedBindingPath), UIRebuildMode.None);
4646
};
4747
viewState.parameterListView.OnDrawVisualElements(rootElement);
4848
}

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ViewBase.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ protected ViewBase(VisualElement root, StateContainer stateContainer)
2626
m_ChildViews = new List<IView>();
2727
}
2828

29-
protected void OnStateChanged(InputActionsEditorState state)
29+
protected void OnStateChanged(InputActionsEditorState state, UIRebuildMode editorRebuildMode)
3030
{
31+
// Return early if rebuilding the editor UI isn't required (ISXB-1171)
32+
if (editorRebuildMode == UIRebuildMode.None)
33+
return;
34+
3135
UpdateView(state);
3236
}
3337

@@ -70,9 +74,9 @@ public void DestroyChildView<TView>(TView view) where TView : IView
7074
view.DestroyView();
7175
}
7276

73-
public void Dispatch(Command command)
77+
public void Dispatch(Command command, UIRebuildMode editorRebuildMode = UIRebuildMode.Rebuild)
7478
{
75-
stateContainer.Dispatch(command);
79+
stateContainer.Dispatch(command, editorRebuildMode);
7680
}
7781

7882
public abstract void RedrawUI(TViewState viewState);

0 commit comments

Comments
 (0)