Skip to content

Commit bdd9937

Browse files
authored
NEW: Duplication via control (win) or command (mac) and "D" key (ISX-1542) (#1767)
* implemented duplication via control (win) or command (mac) key * use control not only for windows * minor refactoring and added changelog
1 parent 8ffd0b4 commit bdd9937

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ however, it has to be formatted properly to pass verification tests.
2121

2222
### Added
2323
- Support for [Game rotation vector](https://developer.android.com/reference/android/hardware/Sensor#TYPE_GAME_ROTATION_VECTOR) sensor on Android
24+
- Duplicate Input Action Items in the new Input Action Asset Editor with Ctrl+D (Windows) or Cmd+D (Mac)
2425

2526
### Fixed
2627
- Partially fixed case ISX-1357 (Investigate performance regressing over time). A sample showed that leaving an InputActionMap enabled could lead to an internal list of listeners growing. This leads to slow-down, so we now warn if we think this is happening.

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionMapsView.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ private void OnKeyDownEvent(KeyDownEvent e)
119119
OnKeyDownEventForRename();
120120
else if (e.keyCode == KeyCode.Delete)
121121
OnKeyDownEventForDelete();
122+
else if (IsDuplicateShortcutPressed(e))
123+
OnKeyDownEventForDuplicate();
122124
}
123125

124126
private void OnKeyDownEventForRename()
@@ -133,6 +135,11 @@ private void OnKeyDownEventForDelete()
133135
item.DeleteItem();
134136
}
135137

138+
private void OnKeyDownEventForDuplicate()
139+
{
140+
((InputActionMapsTreeViewItem)m_ListView.GetRootElementForIndex(m_ListView.selectedIndex))?.DuplicateItem();
141+
}
142+
136143
private readonly CollectionViewSelectionChangeFilter m_ListViewSelectionChangeFilter;
137144
private bool m_EnterRenamingMode;
138145
private readonly VisualElement m_Root;

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionsTreeView.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ private void OnKeyDownEvent(KeyDownEvent e)
252252
OnKeyDownEventForRename();
253253
else if (e.keyCode == KeyCode.Delete)
254254
OnKeyDownEventForDelete();
255+
else if (IsDuplicateShortcutPressed(e))
256+
OnKeyDownEventForDuplicate();
255257
}
256258

257259
private void OnKeyDownEventForRename()
@@ -268,6 +270,11 @@ private void OnKeyDownEventForDelete()
268270
item?.DeleteItem();
269271
}
270272

273+
private void OnKeyDownEventForDuplicate()
274+
{
275+
m_ActionsTreeView.GetRootElementForIndex(m_ActionsTreeView.selectedIndex)?.Q<InputActionsTreeViewItem>()?.DuplicateItem();
276+
}
277+
271278
internal class ViewState
272279
{
273280
public List<TreeViewItemData<ActionOrBindingData>> treeViewData;

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ViewBase.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#if UNITY_EDITOR && UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
22
using System;
33
using System.Collections.Generic;
4+
using UnityEngine.UIElements;
45

56
namespace UnityEngine.InputSystem.Editor
67
{
@@ -33,7 +34,8 @@ public void UpdateView(InputActionsEditorState state)
3334
{
3435
if (m_ViewStateSelector == null)
3536
{
36-
Debug.LogWarning($"View '{GetType().Name}' has no selector and will not render. Create a selector for the " +
37+
Debug.LogWarning(
38+
$"View '{GetType().Name}' has no selector and will not render. Create a selector for the " +
3739
$"view using the CreateSelector method.");
3840
return;
3941
}
@@ -111,6 +113,16 @@ protected void CreateSelector<T1, T2, T3>(
111113
private IViewStateSelector<TViewState> m_ViewStateSelector;
112114
private IList<IView> m_ChildViews;
113115
private bool m_IsFirstUpdate = true;
116+
117+
118+
protected bool IsDuplicateShortcutPressed(KeyDownEvent keyDownEvent)
119+
{
120+
#if UNITY_STANDALONE_OSX
121+
return keyDownEvent.keyCode == KeyCode.D && keyDownEvent.modifiers == EventModifiers.Command;
122+
#else
123+
return keyDownEvent.keyCode == KeyCode.D && keyDownEvent.modifiers == EventModifiers.Control;
124+
#endif
125+
}
114126
}
115127

116128
internal class ViewStateSelector<TReturn> : IViewStateSelector<TReturn>

0 commit comments

Comments
 (0)