Hi,
Did you import the unitypackage in my previous reply? (There's an even newer one at the bottom of this reply.)
The code is in UIPanel.cs. The unitypackage changes this code in OnDisable() (line 142):
Code: Select all
if (InputDeviceManager.autoFocus && UnityEngine.EventSystems.EventSystem.current != null && m_previousSelected != null && !selectables.Contains(m_previousSelected))
{
UnityEngine.EventSystems.EventSystem.current.SetSelectedGameObject(m_previousSelected);
}
This only takes effect in "auto focus" mode -- that is, if the Input Device Manager has detected that you're using a gamepad or keyboard without mouse. If you've used the mouse, this will switch the Input Device Manager to mouse mode. In mouse mode, the code above will be skipped.
OnDisable() is called when the panel's Hide animation is done.
Here are the other areas of code that can chnage the UI selection:
In Close() (line 167), if one of the panel's selectables is currently selected, we select null:
Code: Select all
if (UnityEngine.EventSystems.EventSystem.current != null && selectables.Contains(UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject))
{
UnityEngine.EventSystems.EventSystem.current.SetSelectedGameObject(null);
}
(But this only takes effect if a selectable in the panel is currently selected.)
Close() is called as soon as the panel starts its Hide animation.
In OnVisible() (line 190), if a selectable that is not in the panel is currently selected, we deselect it:
Code: Select all
if (InputDeviceManager.autoFocus && firstSelected != null && m_previousSelected != null && !selectables.Contains(m_previousSelected))
{
var previousSelectable = m_previousSelected.GetComponent<UnityEngine.UI.Selectable>();
if (previousSelectable != null) previousSelectable.OnDeselect(null);
}
OnVisible() is called when the panel's Show animation is done.
Finally, if the Input Device Manager is in "auto focus" mode (gamepad or keyboard), and the focusCheckFrequency is non-zero, it will automatically select a selectable inside the panel. If there are no selectables inside the panel, it will select null. This happens in CheckFocus().
This updated UIPanel.cs changes CheckFocus() so it will not select null if there are no selectables in the panel:
UIPanel_2018-07-20.unitypackage
Here's a test scene:
TestAlertNoSelect_2018-07-20.unitypackage
If you play the scene, it will select a button named "Button". After 1 second, an alert will appear. The button should stay selected during the alert and even after it.
If that doesn't help, can you send me a scene that reproduces the issue? (Let me know what version of Unity to use.)