2
2
using System ;
3
3
using System . Collections . Generic ;
4
4
using System . Linq ;
5
+ using System . Threading . Tasks ;
5
6
using UnityEditor ;
6
7
using UnityEditor . UIElements ;
7
8
using UnityEngine . UIElements ;
@@ -93,7 +94,7 @@ public InputActionsEditorView(VisualElement root, StateContainer stateContainer,
93
94
94
95
// only register the state changed event here in the parent. Changes will be cascaded
95
96
// into child views.
96
- stateContainer . StateChanged += StateChanged ( stateContainer ) ;
97
+ stateContainer . StateChanged += OnStateChanged ;
97
98
98
99
CreateSelector (
99
100
s => s . selectedControlSchemeIndex ,
@@ -106,22 +107,27 @@ public InputActionsEditorView(VisualElement root, StateContainer stateContainer,
106
107
} ) ;
107
108
108
109
s_OnPasteCutElements . Add ( this ) ;
110
+
111
+ Undo . undoRedoPerformed += CheckForInvalidControlSchemeInOneFrame ;
109
112
}
110
113
111
- private Action < InputActionsEditorState , UIRebuildMode > StateChanged ( StateContainer stateContainer )
114
+ private async void CheckForInvalidControlSchemeInOneFrame ( )
112
115
{
113
- return ( inputActionsEditorState , uiRebuildMode ) =>
116
+ try
114
117
{
118
+ await Task . Delay ( 1 ) ;
115
119
var state = stateContainer . GetState ( ) ;
116
120
var viewState = ViewStateSelector . GetViewState ( state ) ;
117
121
var elementAtOrDefault = viewState . controlSchemes ? . ElementAtOrDefault ( viewState . selectedControlSchemeIndex ) ;
118
122
if ( viewState . selectedControlSchemeIndex != - 1 && elementAtOrDefault == default ( InputControlScheme ) )
119
123
{
120
124
m_ControlSchemesView ? . Cancel ( ) ;
121
125
}
122
-
123
- OnStateChanged ( inputActionsEditorState , uiRebuildMode ) ;
124
- } ;
126
+ }
127
+ catch ( Exception e )
128
+ {
129
+ Debug . LogException ( e ) ;
130
+ }
125
131
}
126
132
127
133
private void OnReset ( )
@@ -278,6 +284,7 @@ public override void DestroyView()
278
284
{
279
285
base . DestroyView ( ) ;
280
286
s_OnPasteCutElements . Remove ( this ) ;
287
+ Undo . undoRedoPerformed -= CheckForInvalidControlSchemeInOneFrame ;
281
288
}
282
289
283
290
public void OnPaste ( InputActionsEditorState state )
0 commit comments