Esempio n. 1
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();
        }
Esempio n. 2
0
        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;
                for (var i = actionRow.bindingsCount - 1; i >= 0; i--)
                {
                    action.RemoveBinding(i);
                }
                actionMap.DeleteAction(actionRow.index);
            }

            //Remove action maps
            foreach (var mapRow in FindRowsToDeleteOfType <ActionMapTreeItem>(rows))
            {
                InputActionSerializationHelpers.DeleteActionMap(m_SerializedObject, mapRow.index);
            }

            m_Window.Apply();
            m_Window.OnSelectionChanged();
        }
        public override void DeleteData()
        {
            var assetObject = property.serializedObject;

            if (!(assetObject.targetObject is InputActionAsset))
            {
                throw new InvalidOperationException(
                          $"Action map must be part of InputActionAsset but is in {assetObject.targetObject} instead");
            }

            InputActionSerializationHelpers.DeleteActionMap(assetObject, guid);
        }
Esempio n. 4
0
        private void OnDelete(object data)
        {
            var list = (IList <int>)data;

            // Sort actions by action index such that we delete actions from high to
            // low indices. This way indices won't shift as we delete actions.
            var array = list.Select(x => FindItem(x, rootItem)).ToArray();

            Array.Sort(array, (a, b) =>
            {
                var aActionItem = a as ActionItem;
                var bActionItem = b as ActionItem;

                if (aActionItem != null && bActionItem != null)
                {
                    if (aActionItem.actionIndex < bActionItem.actionIndex)
                    {
                        return(1);
                    }
                    if (aActionItem.actionIndex > bActionItem.actionIndex)
                    {
                        return(-1);
                    }
                }

                return(0);
            });

            // First delete actions, then sets.
            foreach (var item in array)
            {
                if (item is ActionItem)
                {
                    var actionItem    = (ActionItem)item;
                    var actionSetItem = (ActionSetItem)actionItem.parent;
                    InputActionSerializationHelpers.DeleteAction(actionSetItem.property, actionItem.actionIndex);
                }
            }
            foreach (var item in array)
            {
                if (item is ActionSetItem)
                {
                    var actionSetItem = (ActionSetItem)item;
                    InputActionSerializationHelpers.DeleteActionMap(actionSetItem.property.serializedObject, actionSetItem.actionSetIndex);
                }
            }

            m_ApplyAction();
            Reload();
        }
Esempio n. 5
0
        void DeleteSelectedRows()
        {
            var rows = m_TreeView.GetSelectedRows().ToArray();

            foreach (var compositeGroup in rows.Where(r => r.GetType() == typeof(CompositeGroupTreeItem)).OrderByDescending(r => r.index).Cast <CompositeGroupTreeItem>())
            {
                var actionMapProperty = (compositeGroup.parent.parent as InputTreeViewLine).elementProperty;
                var actionProperty    = (compositeGroup.parent as ActionTreeItem).elementProperty;
                for (var i = compositeGroup.children.Count - 1; i >= 0; i--)
                {
                    var composite = (CompositeTreeItem)compositeGroup.children[i];
                    InputActionSerializationHelpers.RemoveBinding(actionProperty, composite.index, actionMapProperty);
                }
                InputActionSerializationHelpers.RemoveBinding(actionProperty, compositeGroup.index, actionMapProperty);
            }
            foreach (var bindingRow in rows.Where(r => r.GetType() == typeof(BindingTreeItem)).OrderByDescending(r => r.index).Cast <BindingTreeItem>())
            {
                var actionMapProperty = (bindingRow.parent.parent as InputTreeViewLine).elementProperty;
                var actionProperty    = (bindingRow.parent as InputTreeViewLine).elementProperty;
                InputActionSerializationHelpers.RemoveBinding(actionProperty, bindingRow.index, actionMapProperty);
            }
            foreach (var actionRow in rows.Where(r => r.GetType() == typeof(ActionTreeItem)).OrderByDescending(r => r.index).Cast <ActionTreeItem>())
            {
                var actionProperty    = (actionRow).elementProperty;
                var actionMapProperty = (actionRow.parent as InputTreeViewLine).elementProperty;

                for (var i = actionRow.bindingsCount - 1; i >= 0; i--)
                {
                    InputActionSerializationHelpers.RemoveBinding(actionProperty, i, actionMapProperty);
                }

                InputActionSerializationHelpers.DeleteAction(actionMapProperty, actionRow.index);
            }
            foreach (var mapRow in rows.Where(r => r.GetType() == typeof(ActionMapTreeItem)).OrderByDescending(r => r.index).Cast <ActionMapTreeItem>())
            {
                InputActionSerializationHelpers.DeleteActionMap(m_SerializedObject, mapRow.index);
            }
            Apply();
            OnSelectionChanged();
        }