Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ however, it has to be formatted properly to pass verification tests.
- [`InputAction.WasCompletedThisFrame`](xref:UnityEngine.InputSystem.InputAction.WasCompletedThisFrame) returns `true` on the frame that the action stopped being in the performed phase. This allows for similar functionality to [`WasPressedThisFrame`](xref:UnityEngine.InputSystem.InputAction.WasPressedThisFrame)/[`WasReleasedThisFrame`](xref:UnityEngine.InputSystem.InputAction.WasReleasedThisFrame) when paired with [`WasPerformedThisFrame`](xref:UnityEngine.InputSystem.InputAction.WasPerformedThisFrame) except it is directly based on the interactions driving the action. For example, you can use it to distinguish between the button being released or whether it was released after being held for long enough to perform when using the Hold interaction.
- Added Copy, Paste and Cut support for Action Maps, Actions and Bindings via context menu and key command shortcuts.
- Added Dual Sense Edge controller to be mapped to the same layout as the Dual Sense controller
- UI Toolkit input action editor now supports showing the derived bindings.

### Fixed
- Fixed syntax of code examples in API documentation for [`AxisComposite`](xref:UnityEngine.InputSystem.Composites.AxisComposite).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,11 @@ public static Command ResetGlobalInputAsset(Action<InputActionAsset> postResetAc
return state;
};
}

public static Command ShowMatchingPaths(bool showMatchingPaths)
{
return (in InputActionsEditorState state) => state.ShowMatchingPaths(showMatchingPaths);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ internal struct InputActionsEditorState
public int selectedBindingIndex { get {return m_selectedBindingIndex; } }
public SelectionType selectionType { get {return m_selectionType; } }
public SerializedObject serializedObject { get; }
public bool showMatchingPaths { get { return m_showMatchingPaths; } }

// Control schemes
public int selectedControlSchemeIndex { get {return m_selectedControlSchemeIndex; } }
Expand All @@ -27,6 +28,7 @@ internal struct InputActionsEditorState
[SerializeField] SelectionType m_selectionType;
[SerializeField] int m_selectedControlSchemeIndex;
[SerializeField] int m_selectedDeviceRequirementIndex;
[SerializeField] bool m_showMatchingPaths;

public InputActionsEditorState(
SerializedObject inputActionAsset,
Expand All @@ -37,7 +39,8 @@ public InputActionsEditorState(
Dictionary<(string, string), HashSet<int>> expandedBindingIndices = null,
InputControlScheme selectedControlScheme = default,
int selectedControlSchemeIndex = -1,
int selectedDeviceRequirementIndex = -1)
int selectedDeviceRequirementIndex = -1,
bool showMatchingPaths = false)
{
serializedObject = inputActionAsset;

Expand All @@ -48,6 +51,7 @@ public InputActionsEditorState(
m_ControlScheme = selectedControlScheme;
this.m_selectedControlSchemeIndex = selectedControlSchemeIndex;
this.m_selectedDeviceRequirementIndex = selectedDeviceRequirementIndex;
this.m_showMatchingPaths = showMatchingPaths;

m_ExpandedCompositeBindings = expandedBindingIndices == null ?
new Dictionary<(string, string), HashSet<int>>() :
Expand All @@ -65,6 +69,7 @@ public InputActionsEditorState(InputActionsEditorState other, SerializedObject a
m_ControlScheme = other.m_ControlScheme;
m_selectedControlSchemeIndex = other.m_selectedControlSchemeIndex;
m_selectedDeviceRequirementIndex = other.m_selectedDeviceRequirementIndex;
m_showMatchingPaths = other.m_showMatchingPaths;

// Editor may leave these as null after domain reloads, so recreate them
m_ExpandedCompositeBindings = (other.m_ExpandedCompositeBindings == null)
Expand All @@ -80,7 +85,8 @@ public InputActionsEditorState With(
InputControlScheme? selectedControlScheme = null,
int? selectedControlSchemeIndex = null,
int? selectedDeviceRequirementIndex = null,
Dictionary<(string, string), HashSet<int>> expandedBindingIndices = null)
Dictionary<(string, string), HashSet<int>> expandedBindingIndices = null,
bool? showMatchingPaths = null)
{
return new InputActionsEditorState(
serializedObject,
Expand All @@ -93,7 +99,9 @@ public InputActionsEditorState With(
// Control schemes
selectedControlScheme ?? this.selectedControlScheme,
selectedControlSchemeIndex ?? this.selectedControlSchemeIndex,
selectedDeviceRequirementIndex ?? this.selectedDeviceRequirementIndex);
selectedDeviceRequirementIndex ?? this.selectedDeviceRequirementIndex,

showMatchingPaths ?? this.showMatchingPaths);
}

public SerializedProperty GetActionMapByName(string actionMapName)
Expand Down Expand Up @@ -198,6 +206,11 @@ public InputActionsEditorState SelectActionMap(int index)
selectedActionIndex: 0, selectionType: SelectionType.Action);
}

public InputActionsEditorState ShowMatchingPaths(bool show)
{
return With(showMatchingPaths: show);
}

public ReadOnlyCollection<int> GetOrCreateExpandedState()
{
return new ReadOnlyCollection<int>(GetOrCreateExpandedStateInternal().ToList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,21 @@
.unity-two-pane-split-view__dragline-anchor {
background-color: rgb(25, 25, 25);
}

#control-scheme-usage-title {
margin: 3px;
-unity-font-style: bold;
}

.matching-controls {
display: none;
}

.matching-controls-shown {
display: flex;
flex-grow: 1;
}

.matching-controls-labels {
margin: 1px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
using System.Linq;
using UnityEditor;
using UnityEngine.UIElements;
using UnityEngine.InputSystem.Layouts;
using UnityEngine.InputSystem.Utilities;
using System.Collections.Generic;

namespace UnityEngine.InputSystem.Editor
{
Expand All @@ -25,7 +28,8 @@ public BindingPropertiesView(VisualElement root, Foldout foldout, StateContainer
selectedBinding = Selectors.GetSelectedBinding(s),
selectedBindingIndex = s.selectedBindingIndex,
selectedBindingPath = Selectors.GetSelectedBindingPath(s),
selectedInputAction = Selectors.GetSelectedAction(s)
selectedInputAction = Selectors.GetSelectedAction(s),
showPaths = stateContainer.GetState().showMatchingPaths
});
}

Expand All @@ -50,6 +54,7 @@ public override void RedrawUI(ViewState viewState)
else if (binding.Value.isPartOfComposite)
{
m_CompositePartBindingPropertiesView = CreateChildView(new CompositePartBindingPropertiesView(rootElement, stateContainer));
DrawMatchingControlPaths(viewState);
DrawControlSchemeToggles(viewState, binding.Value);
}
else
Expand All @@ -64,10 +69,72 @@ public override void RedrawUI(ViewState viewState)
var controlPathContainer = new IMGUIContainer(controlPathEditor.OnGUI);
rootElement.Add(controlPathContainer);

DrawMatchingControlPaths(viewState);
DrawControlSchemeToggles(viewState, binding.Value);
}
}

internal void DrawMatchingControlPaths(ViewState viewState)
{
bool controlPathUsagePresent = false;
List<MatchingControlPath> matchingControlPaths = MatchingControlPath.CollectMatchingControlPaths(viewState.selectedBindingPath.stringValue, viewState.showPaths, ref controlPathUsagePresent);

if (matchingControlPaths == null || matchingControlPaths.Count != 0)
{
var checkbox = new Toggle($"Show Derived Bindings")
{
value = viewState.showPaths
};
rootElement.Add(checkbox);

checkbox.RegisterValueChangedCallback(changeEvent =>
{
Dispatch(Commands.ShowMatchingPaths(changeEvent.newValue));

rootElement.Q(className: "matching-controls").EnableInClassList("matching-controls-shown", changeEvent.newValue);
});
}

if (matchingControlPaths == null)
{
var messageString = controlPathUsagePresent ? "No registered controls match this current binding. Some controls are only registered at runtime." :
"No other registered controls match this current binding. Some controls are only registered at runtime.";

var helpBox = new HelpBox(messageString, HelpBoxMessageType.Warning);
helpBox.AddToClassList("matching-controls");
helpBox.EnableInClassList("matching-controls-shown", viewState.showPaths);
rootElement.Add(helpBox);
}
else if (matchingControlPaths.Count > 0)
{
List<TreeViewItemData<MatchingControlPath>> treeViewMatchingControlPaths = MatchingControlPath.BuildMatchingControlPathsTreeData(matchingControlPaths);

var treeView = new TreeView();
rootElement.Add(treeView);
treeView.AddToClassList("matching-controls");
treeView.EnableInClassList("matching-controls-shown", viewState.showPaths);
treeView.fixedItemHeight = 20;
treeView.SetRootItems(treeViewMatchingControlPaths);

// Set TreeView.makeItem to initialize each node in the tree.
treeView.makeItem = () =>
{
var label = new Label();
label.AddToClassList("matching-controls-labels");
return label;
};

// Set TreeView.bindItem to bind an initialized node to a data item.
treeView.bindItem = (VisualElement element, int index) =>
{
var label = (element as Label);
label.text = treeView.GetItemDataForIndex<MatchingControlPath>(index).path;
};

treeView.ExpandRootItems();
}
}

public override void DestroyView()
{
m_CompositeBindingPropertiesView?.DestroyView();
Expand All @@ -78,7 +145,11 @@ private void DrawControlSchemeToggles(ViewState viewState, SerializedInputBindin
{
if (!viewState.controlSchemes.Any()) return;

var useInControlSchemeLabel = new Label("Use in control scheme");
var useInControlSchemeLabel = new Label("Use in control scheme")
{
name = "control-scheme-usage-title"
};

rootElement.Add(useInControlSchemeLabel);

foreach (var controlScheme in viewState.controlSchemes)
Expand All @@ -103,6 +174,7 @@ internal class ViewState
public InputControlScheme currentControlScheme;
public SerializedProperty selectedBindingPath;
public SerializedInputAction? selectedInputAction;
public bool showPaths;
}
}
}
Expand Down
Loading