1
1
#if UNITY_EDITOR && UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
2
2
using System . Collections . Generic ;
3
+ using System . Threading . Tasks ;
3
4
using UnityEditor ;
4
5
using UnityEditor . ShortcutManagement ;
5
6
using UnityEngine . UIElements ;
@@ -16,6 +17,7 @@ internal class InputActionsEditorSettingsProvider : SettingsProvider
16
17
private bool m_HasEditFocus ;
17
18
private bool m_IgnoreActionChangedCallback ;
18
19
private bool m_IsActivated ;
20
+ private static bool m_IMGUIDropdownVisible ;
19
21
StateContainer m_StateContainer ;
20
22
private static InputActionsEditorSettingsProvider m_ActiveSettingsProvider ;
21
23
@@ -95,6 +97,50 @@ private void OnEditFocus(FocusInEvent @event)
95
97
{
96
98
m_HasEditFocus = true ;
97
99
m_ActiveSettingsProvider = this ;
100
+ SetIMGUIDropdownVisible ( false , false ) ;
101
+ }
102
+ }
103
+
104
+ void SaveAssetOnFocusLost ( )
105
+ {
106
+ #if UNITY_INPUT_SYSTEM_INPUT_ACTIONS_EDITOR_AUTO_SAVE_ON_FOCUS_LOST
107
+ var asset = GetAsset ( ) ;
108
+ if ( asset != null )
109
+ ValidateAndSaveAsset ( asset ) ;
110
+ #endif
111
+ }
112
+
113
+ public static void SetIMGUIDropdownVisible ( bool visible , bool optionWasSelected )
114
+ {
115
+ // If we selected an item from the dropdown, we *should* still be focused on this settings window - but
116
+ // since the IMGUI dropdown is technically a separate window, we have to refocus manually.
117
+ //
118
+ // If we didn't select a dropdown option, there's not a simple way to know where the focus has gone,
119
+ // so assume we lost focus and save if appropriate. ISXB-801
120
+ if ( ! visible && m_IMGUIDropdownVisible )
121
+ {
122
+ if ( optionWasSelected )
123
+ m_ActiveSettingsProvider . m_RootVisualElement . Focus ( ) ;
124
+ else
125
+ m_ActiveSettingsProvider . SaveAssetOnFocusLost ( ) ;
126
+ }
127
+ else if ( visible && ! m_IMGUIDropdownVisible )
128
+ {
129
+ m_ActiveSettingsProvider . m_HasEditFocus = false ;
130
+ }
131
+
132
+ m_IMGUIDropdownVisible = visible ;
133
+ }
134
+
135
+ private async void DelayFocusLost ( bool relatedTargetWasNull )
136
+ {
137
+ await Task . Delay ( 120 ) ;
138
+
139
+ // We delay this call to ensure that the IMGUI flag has a chance to change first.
140
+ if ( relatedTargetWasNull && m_HasEditFocus && ! m_IMGUIDropdownVisible )
141
+ {
142
+ m_HasEditFocus = false ;
143
+ SaveAssetOnFocusLost ( ) ;
98
144
}
99
145
}
100
146
@@ -105,16 +151,7 @@ private void OnEditFocusLost(FocusOutEvent @event)
105
151
// elements outside of project settings Editor Window. Also note that @event is null when we call this
106
152
// from OnDeactivate().
107
153
var element = ( VisualElement ) @event ? . relatedTarget ;
108
- if ( element == null && m_HasEditFocus )
109
- {
110
- m_HasEditFocus = false ;
111
-
112
- #if UNITY_INPUT_SYSTEM_INPUT_ACTIONS_EDITOR_AUTO_SAVE_ON_FOCUS_LOST
113
- var asset = GetAsset ( ) ;
114
- if ( asset != null )
115
- ValidateAndSaveAsset ( asset ) ;
116
- #endif
117
- }
154
+ DelayFocusLost ( element == null ) ;
118
155
}
119
156
120
157
private void OnStateChanged ( InputActionsEditorState newState )
0 commit comments