File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
Assets/Samples/RebindingUI Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change 1+ using UnityEngine . EventSystems ;
2+
13namespace UnityEngine . InputSystem . Samples . RebindUI
24{
35 /// <summary>
@@ -12,11 +14,15 @@ public class CanvasGroupModifier : MonoBehaviour
1214 public bool interactable = false ;
1315
1416 private bool m_SavedInteractable ;
17+ private GameObject m_SelectedObject ;
1518
1619 void OnEnable ( )
1720 {
1821 if ( canvasGroup != null )
1922 {
23+ // Store selection to make sure it is not changed when switching "windows".
24+ m_SelectedObject = EventSystem . current . currentSelectedGameObject ;
25+
2026 // Save current setting and override
2127 m_SavedInteractable = canvasGroup . interactable ;
2228 canvasGroup . interactable = interactable ;
@@ -27,8 +33,14 @@ void OnDisable()
2733 {
2834 if ( canvasGroup != null )
2935 {
30- // Restore previous setting
36+ // Restore previous setting.
3137 canvasGroup . interactable = m_SavedInteractable ;
38+
39+ // Restore previous selection.
40+ if ( m_SelectedObject != null )
41+ EventSystem . current . SetSelectedGameObject ( m_SelectedObject ) ;
42+ else if ( EventSystem . current . currentSelectedGameObject == null )
43+ EventSystem . current . SetSelectedGameObject ( EventSystem . current . firstSelectedGameObject ) ;
3244 }
3345 }
3446 }
You can’t perform that action at this time.
0 commit comments