Example #1
0
        private void HandleCopyEvent()
        {
            if (!CanCopySelection())
            {
                EditorGUIUtility.systemCopyBuffer = null;
                EditorApplication.Beep();
                return;
            }

            var selectedRows = m_TreeView.GetSelectedRows();
            var rowTypes     = selectedRows.Select(r => r.GetType()).Distinct().ToList();

            // Don't allow to copy different type. It will hard to handle pasting
            if (rowTypes.Count() > 1)
            {
                EditorGUIUtility.systemCopyBuffer = null;
                EditorApplication.Beep();
                return;
            }

            var copyList = new StringBuilder(k_InputAssetMarker);

            foreach (var row in selectedRows)
            {
                copyList.Append(row.GetType().Name + "\n");
                copyList.Append(row.SerializeToString());
                copyList.Append(k_InputAssetMarker);
                if (row.hasChildren)
                {
                    CopyChildrenItems(row, copyList);
                }
            }
            EditorGUIUtility.systemCopyBuffer = copyList.ToString();
        }
Example #2
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();
        }
Example #3
0
        public void HandleCopyEvent()
        {
            if (!CanCopySelection())
            {
                EditorGUIUtility.systemCopyBuffer = null;
                EditorApplication.Beep();
                return;
            }

            var selectedRows = m_TreeView.GetSelectedRows();
            var rowTypes     = selectedRows.Select(r => r.GetType()).Distinct().ToList();

            // Don't allow to copy different type. It will hard to handle pasting
            if (rowTypes.Count() > 1)
            {
                EditorGUIUtility.systemCopyBuffer = null;
                EditorApplication.Beep();
                return;
            }

            var copyList = new StringBuilder(kInputAssetMarker);

            foreach (var selectedRow in selectedRows)
            {
                copyList.Append(selectedRow.GetType().Name);
                copyList.Append(selectedRow.SerializeToString());
                copyList.Append(kInputAssetMarker);

                if (selectedRow is ActionTreeItem && selectedRow.children != null && selectedRow.children.Count > 0)
                {
                    var action = selectedRow as ActionTreeItem;

                    foreach (var child in action.children)
                    {
                        if (!(child is BindingTreeItem))
                        {
                            continue;
                        }
                        copyList.Append(child.GetType().Name);
                        copyList.Append((child as BindingTreeItem).SerializeToString());
                        copyList.Append(kInputAssetMarker);
                    }
                }
                if (selectedRow is CompositeGroupTreeItem && selectedRow.children != null && selectedRow.children.Count > 0)
                {
                    var composite = selectedRow as CompositeGroupTreeItem;

                    foreach (var child in composite.children)
                    {
                        if (!(child is CompositeTreeItem))
                        {
                            continue;
                        }
                        copyList.Append(child.GetType().Name);
                        copyList.Append((child as CompositeTreeItem).SerializeToString());
                        copyList.Append(kInputAssetMarker);
                    }
                }
            }
            EditorGUIUtility.systemCopyBuffer = copyList.ToString();
        }