void DeleteSelectedRows(SerializedProperty actionProperty)
        {
            var row     = m_TreeView.GetSelectedRow();
            var rowType = row.GetType();

            // Remove composite bindings
            if (rowType == typeof(CompositeTreeItem))
            {
                for (var i = row.children.Count - 1; i >= 0; i--)
                {
                    var composite = (CompositeTreeItem)row.children[i];

                    InputActionSerializationHelpers.RemoveBinding(actionProperty, composite.index);
                }
                InputActionSerializationHelpers.RemoveBinding(actionProperty, row.index);
            }

            // Remove bindings
            if (rowType == typeof(BindingTreeItem))
            {
                InputActionSerializationHelpers.RemoveBinding(actionProperty, row.index);
            }

            m_TreeView.SetSelection(new List <int>());
            m_TreeView.Reload();
        }
Example #2
0
        private void DeleteSelectedRows()
        {
            var rows     = m_TreeView.GetSelectedRows().ToArray();
            var rowTypes = rows.Select(r => r.GetType()).Distinct().ToList();

            // Don't allow to delete different types at once because it's hard to handle.
            if (rowTypes.Count() > 1)
            {
                EditorApplication.Beep();
                return;
            }

            // Remove composite bindings
            foreach (var compositeGroup in FindRowsToDeleteOfType <CompositeGroupTreeItem>(rows))
            {
                var action = (compositeGroup.parent as ActionTreeItem);
                for (var i = compositeGroup.children.Count - 1; i >= 0; i--)
                {
                    var composite = (CompositeTreeItem)compositeGroup.children[i];
                    action.RemoveBinding(composite.index);
                }
                action.RemoveBinding(compositeGroup.index);
            }

            // Remove bindings
            foreach (var bindingRow in FindRowsToDeleteOfType <BindingTreeItem>(rows))
            {
                var action = bindingRow.parent as ActionTreeItem;
                action.RemoveBinding(bindingRow.index);
            }

            // Remove actions
            foreach (var actionRow in FindRowsToDeleteOfType <ActionTreeItem>(rows))
            {
                var action    = actionRow;
                var actionMap = actionRow.parent as ActionMapTreeItem;

                var bindingsCount = InputActionSerializationHelpers.GetBindingCount(actionMap.bindingsProperty, action.actionName);
                for (var i = bindingsCount - 1; i >= 0; i--)
                {
                    action.RemoveBinding(i);
                }
                actionMap.DeleteAction(actionRow.index);
            }

            //Remove action maps
            foreach (var mapRow in FindRowsToDeleteOfType <ActionMapTreeItem>(rows))
            {
                if (m_SerializedObject == null)
                {
                    throw new InvalidOperationException("Deleting action map is not a valid operation");
                }
                InputActionSerializationHelpers.DeleteActionMap(m_SerializedObject, mapRow.index);
            }

            m_TreeView.SetSelection(new List <int>());
            m_Apply();
        }