Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,43 @@ public static Command SelectActionMap(string actionMapName)
return (in InputActionsEditorState state) => state.SelectActionMap(actionMapName);
}

public static Command AddActionMap()
{
return (in InputActionsEditorState state) =>
{
var newMap = InputActionSerializationHelpers.AddActionMap(state.serializedObject);
var actionProperty = InputActionSerializationHelpers.AddAction(newMap);
InputActionSerializationHelpers.AddBinding(actionProperty, newMap);
Comment thread
ritamerkl marked this conversation as resolved.
state.serializedObject.ApplyModifiedProperties();
return state.SelectActionMap(newMap);
};
}

public static Command AddAction()
{
return (in InputActionsEditorState state) =>
{
var actionMap = Selectors.GetSelectedActionMap(state).wrappedProperty;
var newAction = InputActionSerializationHelpers.AddAction(actionMap);
InputActionSerializationHelpers.AddBinding(newAction, actionMap);
Comment thread
ritamerkl marked this conversation as resolved.
state.serializedObject.ApplyModifiedProperties();
return state.SelectAction(newAction);
};
}

public static Command AddBinding()
{
return (in InputActionsEditorState state) =>
{
var action = Selectors.GetSelectedAction(state).wrappedProperty;
var map = Selectors.GetSelectedActionMap(state).wrappedProperty;
var binding = InputActionSerializationHelpers.AddBinding(action, map);
var bindingIndex = new SerializedInputBinding(binding).indexOfBinding;
state.serializedObject.ApplyModifiedProperties();
return state.With(selectedBindingIndex: bindingIndex, selectionType: SelectionType.Binding);
};
}

public static Command ExpandCompositeBinding(SerializedInputBinding binding)
{
return (in InputActionsEditorState state) => state.ExpandCompositeBinding(binding);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,18 @@ public InputActionsEditorState SelectAction(string actionName)
throw new InvalidOperationException($"Couldn't find an action map with name '{actionName}'.");
}

public InputActionsEditorState SelectAction(SerializedProperty state)
{
var index = state.GetIndexOfArrayElement();
return With(selectedActionIndex: index, selectionType: SelectionType.Action);
}

public InputActionsEditorState SelectActionMap(SerializedProperty state)
{
var index = state.GetIndexOfArrayElement();
return With(selectedBindingIndex: 0, selectedActionMapIndex: index, selectedActionIndex: 0);
}

public InputActionsEditorState SelectActionMap(string actionMapName)
{
var actionMap = GetActionMapByName(actionMapName);
Expand All @@ -160,6 +172,11 @@ public InputActionsEditorState SelectActionMap(string actionMapName)
selectedActionIndex: 0);
}

public InputActionsEditorState SelectBinding(int index)
{
return With(selectedBindingIndex: index);
}

public ReadOnlyCollection<int> GetOrCreateExpandedState()
{
return new ReadOnlyCollection<int>(GetOrCreateExpandedStateInternal().ToList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
</ui:VisualElement>
<ui:TwoPaneSplitView name="actions-and-properties-split-view" fixed-pane-index="1" fixed-pane-initial-dimension="400" style="height: auto;">
<ui:VisualElement name="actions-container" class="body-panel-container">
<ui:VisualElement name="header" class="body-panel-header">
<ui:VisualElement name="header" class="body-panel-header" style="justify-content: space-between;">
<ui:Label text="Actions" display-tooltip-when-elided="true" name="actions-label" />
<ui:Button text="+" display-tooltip-when-elided="true" name="add-new-action-button" style="align-items: auto;" />
</ui:VisualElement>
<ui:VisualElement name="body">
<ui:TreeView view-data-key="unity-tree-view" focusable="true" name="actions-tree-view" show-border="false" reorderable="true" show-alternating-row-backgrounds="None" fixed-item-height="20" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
border-width: 0;
}

#add-new-action-button {
background-color: transparent;
border-width: 0;
}

#bindings-container {
min-width: 225px;
border-left-width: 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
<Style src="project://database/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Resources/InputActionsEditorStyles.uss?fileID=7433441132597879392&amp;guid=7dac9c49a90bca4499371d0adc9b617b&amp;type=3#InputActionsEditorStyles" />
<ui:VisualElement name="item-row" class="unity-list-view__item" style="flex-direction: row; flex-grow: 1; justify-content: flex-start; margin-left: 4px; flex-shrink: 0;">
<ui:VisualElement name="item-row" class="unity-list-view__item" style="flex-direction: row; flex-grow: 1; justify-content: space-between; margin-left: 4px; flex-shrink: 0;">
<ui:VisualElement name="row" style="flex-direction: row; border-left-width: 0; border-left-color: rgb(89, 89, 89); justify-content: flex-start; align-items: center;">
<ui:VisualElement name="icon" style="justify-content: center; background-image: url(&apos;project://database/Packages/com.unity.inputsystem/InputSystem/Editor/Icons/d_InputControl.png?fileID=2800000&amp;guid=399cd90f4e31041e692a7d3a8b1aa4d0&amp;type=3#d_InputControl&apos;); width: 16px; height: 16px;" />
<ui:TextField picking-mode="Ignore" name="rename-text-field" is-delayed="true" focusable="true" class="unity-input-actions-editor-hidden" style="visibility: visible; flex-shrink: 1;" />
<ui:Label text="binding-name" display-tooltip-when-elided="true" name="name" style="flex-grow: 1; justify-content: center; align-items: stretch; margin-left: 4px; -unity-font-style: normal;" />
</ui:VisualElement>
<ui:Button text="+" display-tooltip-when-elided="true" enable-rich-text="false" name="add-new-binding-button" style="opacity: 1; background-color: rgba(255, 255, 255, 0); border-left-color: rgba(255, 255, 255, 0); border-right-color: rgba(255, 255, 255, 0); border-top-color: rgba(255, 255, 255, 0); border-bottom-color: rgba(255, 255, 255, 0); display: none; align-items: flex-end; align-self: auto; flex-direction: row-reverse;" />
</ui:VisualElement>
</ui:UXML>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#if UNITY_EDITOR && UNITY_2022_1_OR_NEWER
using System.Collections.Generic;
using System.Linq;
using UnityEngine.InputSystem.Utilities;
using UnityEngine.UIElements;

namespace UnityEngine.InputSystem.Editor
Expand Down Expand Up @@ -33,25 +34,23 @@ public ActionMapsView(VisualElement root, StateContainer stateContainer)

CreateSelector(s => new ViewStateCollection<string>(Selectors.GetActionMapNames(s)),
(actionMapNames, state) => new ViewState(Selectors.GetSelectedActionMap(state), actionMapNames));

addActionMapButton.clicked += AddActionMap;
}

private Button addActionMapButton => m_Root?.Q<Button>("add-new-action-map-button");

public override void RedrawUI(ViewState viewState)
{
m_ListView.bindItem = (element, i) =>
Comment thread
ritamerkl marked this conversation as resolved.
{
var treeViewItem = (InputActionsTreeViewItem)element;
treeViewItem.label.text = (string)m_ListView.itemsSource[i];
};
m_ListView.makeItem = () => new InputActionsTreeViewItem();
m_ListView.itemsSource = viewState.actionMapNames?.ToList() ?? new List<string>();
addActionMapButton.clicked += ShowAddActionMapWindow;
var indexOf = viewState.actionMapNames.IndexOf(viewState.selectedActionMap.name);
m_ListView.SetSelection(indexOf);
m_ListView.Rebuild();
}

public override void DestroyView()
{
addActionMapButton.clicked -= ShowAddActionMapWindow;
addActionMapButton.clicked -= AddActionMap;
}

private void ChangeActionMapName(string newName)
Expand All @@ -64,8 +63,9 @@ private void SelectActionMap()
Dispatch(Commands.SelectActionMap((string)m_ListView.selectedItem));
}

private void ShowAddActionMapWindow()
private void AddActionMap()
{
Dispatch(Commands.AddActionMap());
}

private readonly VisualElement m_Root;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal class ActionsTreeView : ViewBase<ActionsTreeView.ViewState>
{
private readonly VisualElement m_Root;
private readonly TreeView m_ActionsTreeView;
private Button addActionButton => m_Root?.Q<Button>("add-new-action-button");

public ActionsTreeView(VisualElement root, StateContainer stateContainer)
: base(stateContainer)
Expand All @@ -31,6 +32,14 @@ public ActionsTreeView(VisualElement root, StateContainer stateContainer)
var item = m_ActionsTreeView.GetItemDataForIndex<ActionOrBindingData>(i);

e.Q<Label>("name").text = item.name;
var addBindingButton = e.Q<Button>("add-new-binding-button");
if (item.isAction)
{
addBindingButton.style.display = DisplayStyle.Flex;
addBindingButton.clicked += () => AddBinding(item.name);
}
else
addBindingButton.style.display = DisplayStyle.None;

if (!string.IsNullOrEmpty(item.controlLayout))
e.Q<VisualElement>("icon").style.backgroundImage =
Expand All @@ -49,19 +58,69 @@ public ActionsTreeView(VisualElement root, StateContainer stateContainer)
};

CreateSelector(Selectors.GetActionsForSelectedActionMap,
(_, state) => new ViewState {treeViewData = Selectors.GetActionsAsTreeViewData(state)});
(_, state) =>
{
var treeData = Selectors.GetActionsAsTreeViewData(state);
return new ViewState
{
treeViewData = treeData,
newElementID = state.selectionType == SelectionType.Action ? treeData[state.selectedActionIndex].id : GetComponentOrBindingID(treeData, state.selectedBindingIndex)
};
});

addActionButton.clicked += AddAction;
}

private int GetComponentOrBindingID(List<TreeViewItemData<ActionOrBindingData>> treeList, int selectedBindingIndex)
{
var currentBindingIndex = -1;
foreach (var action in treeList)
{
foreach (var bindingOrComponent in action.children)
{
currentBindingIndex++;
if (currentBindingIndex == selectedBindingIndex) return bindingOrComponent.id;
if (bindingOrComponent.hasChildren)
{
foreach (var binding in bindingOrComponent.children)
{
currentBindingIndex++;
if (currentBindingIndex == selectedBindingIndex) return binding.id;
}
}
}
}
return -1;
}

public override void DestroyView()
{
addActionButton.clicked -= AddAction;
}

public override void RedrawUI(ViewState viewState)
{
m_ActionsTreeView.Clear();
m_ActionsTreeView.SetRootItems(viewState.treeViewData);
m_ActionsTreeView.SetSelectionById(viewState.newElementID);
m_ActionsTreeView.Rebuild();
}

private void AddAction()
{
Dispatch(Commands.AddAction());
}

private void AddBinding(string actionName)
{
Dispatch(Commands.SelectAction(actionName));
Dispatch(Commands.AddBinding());
}

internal class ViewState
{
public List<TreeViewItemData<ActionOrBindingData>> treeViewData;
public int newElementID;
}
}

Expand Down Expand Up @@ -134,7 +193,7 @@ public static List<TreeViewItemData<ActionOrBindingData>> GetActionsAsTreeViewDa
i--;
bindingItems.Add(new TreeViewItemData<ActionOrBindingData>(id++,
new ActionOrBindingData(false, serializedInputBinding.name, action.expectedControlType, serializedInputBinding.indexOfBinding),
compositeItems));
compositeItems.Count > 0 ? compositeItems : null));
}
else
{
Expand All @@ -143,9 +202,8 @@ public static List<TreeViewItemData<ActionOrBindingData>> GetActionsAsTreeViewDa
GetControlLayout(serializedInputBinding.path), serializedInputBinding.indexOfBinding)));
}
}

actionItems.Add(new TreeViewItemData<ActionOrBindingData>(id++,
new ActionOrBindingData(true, action.name, action.expectedControlType), bindingItems));
new ActionOrBindingData(true, action.name, action.expectedControlType), bindingItems.Count > 0 ? bindingItems : null));
}
return actionItems;
}
Expand Down