Skip to content

Commit 1e82e6b

Browse files
authored
Merge branch 'develop' into ci/coverage-report-merge
2 parents cd53170 + b850953 commit 1e82e6b

File tree

12 files changed

+285
-35
lines changed

12 files changed

+285
-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: 5 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.
@@ -45,6 +49,7 @@ however, it has to be formatted properly to pass verification tests.
4549
### Added
4650
- Added new API `InputSystem.settings.useIMGUIEditorForAssets` that should be used in custom `InputParameterEditor` that use both IMGUI and UI Toolkit.
4751
- Added ProfilerMakers to `InputAction.Enable()` and `InputActionMap.ResolveBindings()` to enable gathering of profiling data.
52+
- Added throwing an error message when trying to use the Input System package on console without the extension package installed.
4853

4954
## [1.11.2] - 2024-10-16
5055

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)
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#if ((UNITY_EDITOR && UNITY_2021_1_OR_NEWER) || PACKAGE_DOCS_GENERATION)
2+
using System;
3+
using System.Collections.Generic;
4+
using UnityEditor;
5+
6+
namespace UnityEngine.InputSystem.Editor
7+
{
8+
/// <summary>
9+
/// This class controls all required plugins and extension packages are installed for the InputSystem.
10+
/// </summary>
11+
/// <remarks>
12+
/// For some platforms, the InputSystem requires additional plugins to be installed. This class checks if the required plugins are installed and throws a warning if they are not.
13+
/// </remarks>
14+
public class InputSystemPluginControl
15+
{
16+
// Input system platform specific classes register with the input system via a class using InitializeOnLoad on static constructors.
17+
// Static constructors in classes that are tagged with the InitializeOnLoad attribute are called before methods using the InitializeOnLoadMethod attribute.
18+
// So the extra input system packages will be registered before this check which is done in InitializeOnLoadMethod.
19+
[InitializeOnLoadMethod]
20+
private static void CheckForExtension()
21+
{
22+
ThrowWarningOnMissingPlugin();
23+
}
24+
25+
// This static HashSet will be reset OnDomainReload and so it will be reset every Domain Reload (at the time of InitializeOnLoad).
26+
// This is pre-populated with the list of platforms that don't need a extra platform specific input system package to add platform specific functionality.
27+
private static HashSet<BuildTarget> s_supportedBuildTargets = new HashSet<BuildTarget>()
28+
{
29+
BuildTarget.StandaloneOSX,
30+
BuildTarget.StandaloneWindows,
31+
BuildTarget.iOS,
32+
BuildTarget.Android,
33+
BuildTarget.StandaloneWindows64,
34+
BuildTarget.WebGL,
35+
BuildTarget.WSAPlayer,
36+
BuildTarget.StandaloneLinux64,
37+
BuildTarget.tvOS,
38+
BuildTarget.LinuxHeadlessSimulation,
39+
BuildTarget.EmbeddedLinux,
40+
#if UNITY_2022_1_OR_NEWER
41+
BuildTarget.QNX,
42+
#endif
43+
#if UNITY_2023_3_OR_NEWER
44+
BuildTarget.VisionOS,
45+
#endif
46+
#if UNITY_6000_0_OR_NEWER
47+
BuildTarget.ReservedCFE,
48+
#endif
49+
#if UNITY_6000_0_7_OR_NEWER
50+
BuildTarget.Kepler
51+
#endif
52+
BuildTarget.NoTarget
53+
};
54+
55+
static bool BuildTargetNeedsPlugin()
56+
{
57+
BuildTarget target = EditorUserBuildSettings.activeBuildTarget;
58+
foreach (var platform in s_supportedBuildTargets)
59+
{
60+
if (platform == target) return false;
61+
}
62+
return true;
63+
}
64+
65+
private const string PlugInName = "com.unity.inputsystem.";
66+
67+
/// <summary>
68+
/// Used to register extensions externally to the InputSystem, this is needed for all Platforms that require a plugin to be installed.
69+
/// </summary>
70+
/// <remarks>
71+
/// This method is internally called by the InputSystem package extensions to register the PlugIn. This can be called for custom extensions on custom platforms.
72+
/// </remarks>
73+
public static void RegisterPlatform(BuildTarget target)
74+
{
75+
s_supportedBuildTargets.Add(target);
76+
}
77+
78+
private static bool IsPluginInstalled()
79+
{
80+
var registeredPackages = UnityEditor.PackageManager.PackageInfo.GetAllRegisteredPackages();
81+
var plugInName = PlugInName + EditorUserBuildSettings.activeBuildTarget.ToString().ToLower();
82+
foreach (var package in registeredPackages)
83+
{
84+
if (package.name.Equals(plugInName))
85+
return true;
86+
}
87+
return false;
88+
}
89+
90+
private static void ThrowWarningOnMissingPlugin()
91+
{
92+
if (!BuildTargetNeedsPlugin())
93+
return;
94+
Debug.Assert(IsPluginInstalled(), "Active Input Handling is set to InputSystem, but no Plugin for " + EditorUserBuildSettings.activeBuildTarget + " was found. Please install the missing InputSystem package extensions.");
95+
}
96+
}
97+
}
98+
#endif

Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPluginControl.cs.meta

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

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
}

0 commit comments

Comments
 (0)