Skip to content

Commit 242f27e

Browse files
committed
fix: missed check-in
1 parent 0047e16 commit 242f27e

1 file changed

Lines changed: 30 additions & 25 deletions

File tree

Packages/com.unity.inputsystem/InputSystem/Editor/DeviceSimulator/InputSystemPlugin.cs

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,44 @@ private void OnUpdate()
7878
return;
7979

8080
m_LastFocusedWindow = focusedWindow;
81-
var simulatorFocused =
82-
m_RootElement != null
83-
&& focusedWindow != null
81+
var simulatorFocused =
82+
m_RootElement != null
83+
&& focusedWindow != null
8484
&& focusedWindow.rootVisualElement.panel == m_RootElement.panel;
8585

86-
if (simulatorFocused && !m_ConflictingDevicesDisabled)
86+
SetConflictingDevicesDisabled(simulatorFocused);
87+
}
88+
89+
// Exposed internally so tests can drive the focus transition without a live SimulatorWindow.
90+
// OnUpdate itself can't run in a unit test: it needs play mode and a real panel to compare against.
91+
internal void SetConflictingDevicesDisabled(bool disabled)
92+
{
93+
if (disabled == m_ConflictingDevicesDisabled)
94+
return;
95+
96+
if (disabled)
8797
{
8898
// UGUI elements like a button don't get pressed when multiple pointers for example mouse and touchscreen are sending data at the same time
8999
foreach (var device in InputSystem.devices)
90100
DisableConflictingDevice(device);
91-
m_ConflictingDevicesDisabled = true;
92101
}
93-
else if (!simulatorFocused && m_ConflictingDevicesDisabled)
102+
else
94103
{
95-
ReenableConflictingDevices();
96-
m_ConflictingDevicesDisabled = false;
104+
foreach (var device in m_DisabledDevices)
105+
{
106+
// Note that m_Quitting is used here to mitigate the problem reported in issue tracker:
107+
// https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-10774.
108+
// Enabling a device will call into IOCTL of backend which may be destroyed prior
109+
// to this callback on Unity version. This is not a fix for the actual problem
110+
// of shutdown order but a package fix to mitigate this problem.
111+
// The core problem with the destruction order was still there in Unity 6.5.
112+
if (device.added && !m_Quitting)
113+
InputSystem.EnableDevice(device);
114+
}
115+
m_DisabledDevices.Clear();
97116
}
117+
118+
m_ConflictingDevicesDisabled = disabled;
98119
}
99120

100121
private void DisableConflictingDevice(InputDevice device)
@@ -106,22 +127,6 @@ private void DisableConflictingDevice(InputDevice device)
106127
}
107128
}
108129

109-
private void ReenableConflictingDevices()
110-
{
111-
foreach (var device in m_DisabledDevices)
112-
{
113-
// Note that m_Quitting is used here to mitigate the problem reported in issue tracker:
114-
// https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-10774.
115-
// Enabling a device will call into IOCTL of backend which may be destroyed prior
116-
// to this callback on Unity version. This is not a fix for the actual problem
117-
// of shutdown order but a package fix to mitigate this problem.
118-
// The core problem with the destruction order was still there in Unity 6.5.
119-
if (device.added && !m_Quitting)
120-
InputSystem.EnableDevice(device);
121-
}
122-
m_DisabledDevices.Clear();
123-
}
124-
125130
private void OnDeviceChange(InputDevice device, InputDeviceChange change)
126131
{
127132
// Only disable newly added/reconnected devices while the simulator is the active window.
@@ -166,7 +171,7 @@ public override void OnDestroy()
166171
if (SimulatorTouchscreen != null)
167172
InputSystem.RemoveDevice(SimulatorTouchscreen);
168173

169-
ReenableConflictingDevices();
174+
SetConflictingDevicesDisabled(false);
170175
m_RootElement = null;
171176
}
172177
}

0 commit comments

Comments
 (0)