1
1
#if UNITY_EDITOR && UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
2
+ using CmdEvents = UnityEngine . InputSystem . Editor . InputActionsEditorConstants . CommandEvents ;
2
3
using System ;
3
4
using System . Collections . Generic ;
4
5
using System . Linq ;
@@ -14,6 +15,8 @@ internal class InputActionsEditorView : ViewBase<InputActionsEditorView.ViewStat
14
15
private const string autoSaveToggleId = "auto-save-toolbar-toggle" ;
15
16
private const string menuButtonId = "asset-menu" ;
16
17
18
+ private readonly TreeView m_ActionsTreeView ;
19
+ private readonly ListView m_ActionMapsListView ;
17
20
private readonly ToolbarMenu m_MenuButtonToolbar ;
18
21
private readonly ToolbarButton m_SaveButton ;
19
22
@@ -71,6 +74,13 @@ public InputActionsEditorView(VisualElement root, StateContainer stateContainer)
71
74
controlSchemes = controlSchemes ,
72
75
selectedControlSchemeIndex = state . selectedControlSchemeIndex
73
76
} ) ;
77
+
78
+ m_ActionsTreeView = root . Q < TreeView > ( "actions-tree-view" ) ;
79
+ m_ActionMapsListView = root . Q < ListView > ( "action-maps-list-view" ) ;
80
+
81
+ root . RegisterCallback < ValidateCommandEvent > ( OnValidateCommand ) ;
82
+ root . RegisterCallback < ExecuteCommandEvent > ( OnExecuteCommand ) ;
83
+ root . focusable = true ; // Required for CommandEvents to work
74
84
}
75
85
76
86
private void OnReset ( )
@@ -159,6 +169,49 @@ public class ViewState
159
169
public IEnumerable < InputControlScheme > controlSchemes ;
160
170
public int selectedControlSchemeIndex ;
161
171
}
172
+
173
+ void OnExecuteCommand ( ExecuteCommandEvent evt )
174
+ {
175
+ if ( evt . commandName != CmdEvents . Paste )
176
+ return ;
177
+
178
+ var copiedType = CopyPasteHelper . GetCopiedClipboardType ( ) ;
179
+
180
+ if ( copiedType == typeof ( InputActionMap ) )
181
+ {
182
+ Dispatch ( Commands . PasteActionMaps ( ) ) ;
183
+ }
184
+ else if ( copiedType == typeof ( InputAction ) )
185
+ {
186
+ // Can't paste an Action without any Action Maps for it to go to
187
+ if ( m_ActionMapsListView . itemsSource . Count > 0 )
188
+ Dispatch ( Commands . PasteActionsOrBindings ( ) ) ;
189
+ }
190
+ else if ( copiedType == typeof ( InputBinding ) )
191
+ {
192
+ // Can't paste a Binding without any Actions for it to go to
193
+ if ( m_ActionsTreeView . itemsSource . Count > 0 )
194
+ {
195
+ var oldSelectedBinding = stateContainer . GetState ( ) . selectedBindingIndex ;
196
+ Dispatch ( Commands . PasteActionsOrBindings ( ) ) ;
197
+
198
+ // If paste succeeded, expand the relevant Action to show the new binding.
199
+ if ( stateContainer . GetState ( ) . selectedBindingIndex != oldSelectedBinding )
200
+ m_ActionsTreeView . ExpandItem ( m_ActionsTreeView . GetIdForIndex ( stateContainer . GetState ( ) . selectedActionIndex ) ) ;
201
+ }
202
+ }
203
+ }
204
+
205
+ void OnValidateCommand ( ValidateCommandEvent evt )
206
+ {
207
+ // Mark commands as supported for Execute by stopping propagation of the event
208
+ switch ( evt . commandName )
209
+ {
210
+ case CmdEvents . Paste :
211
+ evt . StopPropagation ( ) ;
212
+ break ;
213
+ }
214
+ }
162
215
}
163
216
164
217
internal static partial class Selectors
0 commit comments