diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorState.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorState.cs index 74e4e52442..24a0193549 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorState.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorState.cs @@ -1,7 +1,6 @@ #if UNITY_EDITOR && UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS using System; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.Linq; using UnityEditor; @@ -92,7 +91,6 @@ public InputActionsEditorState( int selectedActionIndex = 0, int selectedBindingIndex = 0, SelectionType selectionType = SelectionType.Action, - Dictionary<(string, string), HashSet> expandedBindingIndices = null, InputControlScheme selectedControlScheme = default, int selectedControlSchemeIndex = -1, int selectedDeviceRequirementIndex = -1, @@ -112,9 +110,6 @@ public InputActionsEditorState( m_selectedControlSchemeIndex = selectedControlSchemeIndex; m_selectedDeviceRequirementIndex = selectedDeviceRequirementIndex; - m_ExpandedCompositeBindings = expandedBindingIndices == null ? - new Dictionary<(string, string), HashSet>() : - new Dictionary<(string, string), HashSet>(expandedBindingIndices); m_CutElements = cutElements; } @@ -201,12 +196,6 @@ public InputActionsEditorState(InputActionsEditorState other, SerializedObject a m_ControlScheme = new InputControlScheme(); } - // Editor may leave these as null after domain reloads, so recreate them in that case. - // If they exist, we attempt to just preserve the same expanded items based on name for now for simplicity. - m_ExpandedCompositeBindings = other.m_ExpandedCompositeBindings == null ? - new Dictionary<(string, string), HashSet>() : - new Dictionary<(string, string), HashSet>(other.m_ExpandedCompositeBindings); - m_CutElements = other.cutElements; } @@ -218,7 +207,6 @@ public InputActionsEditorState With( InputControlScheme? selectedControlScheme = null, int? selectedControlSchemeIndex = null, int? selectedDeviceRequirementIndex = null, - Dictionary<(string, string), HashSet> expandedBindingIndices = null, List cutElements = null) { return new InputActionsEditorState( @@ -228,7 +216,6 @@ public InputActionsEditorState With( selectedActionIndex ?? this.selectedActionIndex, selectedBindingIndex ?? this.selectedBindingIndex, selectionType ?? this.selectionType, - expandedBindingIndices ?? m_ExpandedCompositeBindings, // Control schemes selectedControlScheme ?? this.selectedControlScheme, @@ -248,7 +235,6 @@ public InputActionsEditorState ClearCutElements() selectedActionIndex, selectedBindingIndex, selectionType, - m_ExpandedCompositeBindings, selectedControlScheme, selectedControlSchemeIndex, selectedDeviceRequirementIndex, @@ -262,39 +248,6 @@ public SerializedProperty GetActionMapByName(string actionMapName) .FirstOrDefault(p => p.FindPropertyRelative(nameof(InputActionMap.m_Name)).stringValue == actionMapName); } - public InputActionsEditorState ExpandCompositeBinding(SerializedInputBinding binding) - { - var key = GetSelectedActionMapAndActionKey(); - - var expandedCompositeBindings = new Dictionary<(string, string), HashSet>(m_ExpandedCompositeBindings); - if (!expandedCompositeBindings.TryGetValue(key, out var expandedStates)) - { - expandedStates = new HashSet(); - expandedCompositeBindings.Add(key, expandedStates); - } - - expandedStates.Add(binding.indexOfBinding); - - return With(expandedBindingIndices: expandedCompositeBindings); - } - - public InputActionsEditorState CollapseCompositeBinding(SerializedInputBinding binding) - { - var key = GetSelectedActionMapAndActionKey(); - - if (m_ExpandedCompositeBindings.ContainsKey(key) == false) - throw new InvalidOperationException("Trying to collapse a composite binding tree that was never expanded."); - - // do the dance of C# immutability - var oldExpandedCompositeBindings = m_ExpandedCompositeBindings; - var expandedCompositeBindings = oldExpandedCompositeBindings.Keys.Where(dictKey => dictKey != key) - .ToDictionary(dictKey => dictKey, dictKey => oldExpandedCompositeBindings[dictKey]); - var newHashset = new HashSet(m_ExpandedCompositeBindings[key].Where(index => index != binding.indexOfBinding)); - expandedCompositeBindings.Add(key, newHashset); - - return With(expandedBindingIndices: expandedCompositeBindings); - } - public InputActionsEditorState SelectAction(string actionName) { var actionMap = GetSelectedActionMap(); @@ -419,48 +372,11 @@ public readonly List GetCutElements() return m_CutElements; } - public ReadOnlyCollection GetOrCreateExpandedState() - { - return new ReadOnlyCollection(GetOrCreateExpandedStateInternal().ToList()); - } - - private HashSet GetOrCreateExpandedStateInternal() - { - var key = GetSelectedActionMapAndActionKey(); - - if (m_ExpandedCompositeBindings.TryGetValue(key, out var expandedStates)) - return expandedStates; - - expandedStates = new HashSet(); - m_ExpandedCompositeBindings.Add(key, expandedStates); - return expandedStates; - } - - internal (string, string) GetSelectedActionMapAndActionKey() - { - var selectedActionMap = GetSelectedActionMap(); - - var selectedAction = selectedActionMap - .FindPropertyRelative(nameof(InputActionMap.m_Actions)) - .GetArrayElementAtIndex(selectedActionIndex); - - var key = ( - selectedActionMap.FindPropertyRelative(nameof(InputActionMap.m_Name)).stringValue, - selectedAction.FindPropertyRelative(nameof(InputAction.m_Name)).stringValue - ); - return key; - } - private SerializedProperty GetSelectedActionMap() { return Selectors.GetActionMapAtIndex(serializedObject, selectedActionMapIndex)?.wrappedProperty; } - /// - /// Expanded states for the actions tree view. These are stored per InputActionMap - /// - private readonly Dictionary<(string, string), HashSet> m_ExpandedCompositeBindings; - private readonly InputControlScheme m_ControlScheme; } diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionsTreeView.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionsTreeView.cs index a0b6029a9b..9609e72c2d 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionsTreeView.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionsTreeView.cs @@ -659,9 +659,12 @@ public static List> GetActionsAsTreeViewDa private static int GetIdForGuid(Guid guid, Dictionary idDictionary) { + // This method is used to ensure that the same Guid always gets the same id + // We use getHashCode instead of a counter, as we cannot guarantee that the same Guid will always be added in the same order + // There is a tiny chance of a collision, but it is it does happen it will only affect the expanded state of the tree view if (!idDictionary.TryGetValue(guid, out var id)) { - id = idDictionary.Values.Count > 0 ? idDictionary.Values.Max() + 1 : 0; + id = guid.GetHashCode(); idDictionary.Add(guid, id); } return id;