void AddBinding(object propertyObj)
        {
            if (!CanAddBinding())
            {
                return;
            }
            var actionMapProperty = (SerializedProperty)propertyObj;
            var action            = m_TreeView.GetSelectedAction();

            InputActionSerializationHelpers.AppendBinding(action.elementProperty, actionMapProperty);
            action.elementProperty.serializedObject.ApplyModifiedProperties();
            m_TreeView.Reload();
        }
        private void AddAddOptionsToMenu(GenericMenu menu, bool isContextMenu)
        {
            var hasSelection  = m_TreeView.HasSelection();
            var canAddBinding = false;
            var action        = m_TreeView.GetSelectedAction();

            if (action != null && hasSelection)
            {
                canAddBinding = true;
            }
            var canAddAction = false;
            var actionMap    = m_TreeView.GetSelectedActionMap();

            if (actionMap != null && hasSelection)
            {
                canAddAction = true;
            }
            if (canAddBinding)
            {
                menu.AddItem(isContextMenu ? m_AddBindingContextGUI : m_AddBindingGUI, false, OnAddBinding);
            }
            else if (!isContextMenu)
            {
                menu.AddDisabledItem(m_AddBindingGUI);
            }
            if (canAddAction)
            {
                menu.AddItem(isContextMenu ? m_AddActionContextGUI : m_AddActionGUI, false, OnAddAction);
            }
            else if (!isContextMenu)
            {
                menu.AddDisabledItem(m_AddActionGUI, false);
            }
            menu.AddItem(isContextMenu ?  m_AddActionMapContextGUI : m_AddActionMapGUI, false, OnAddActionMap);

            var compositeString = isContextMenu ? EditorGUIUtility.TrTextContent("Add composite") : EditorGUIUtility.TrTextContent("Composite");

            if (canAddBinding)
            {
                foreach (var composite in InputBindingComposite.s_Composites.names)
                {
                    menu.AddItem(new GUIContent(compositeString.text + "/" + composite), false, OnAddCompositeBinding, composite);
                }
            }
            else if (!isContextMenu)
            {
                menu.AddDisabledItem(new GUIContent(compositeString), false);
            }
        }
Beispiel #3
0
        void AddAddOptionsToMenu(GenericMenu menu, bool includeAddPrefix)
        {
            var hasSelection  = m_TreeView.HasSelection();
            var canAddBinding = false;
            var row           = m_TreeView.GetSelectedAction();

            if (row != null && hasSelection)
            {
                canAddBinding = true;
            }

            var canAddAction = false;
            var action       = m_TreeView.GetSelectedActionMap();

            if (action != null && hasSelection)
            {
                canAddAction = true;
            }

            var actionString = includeAddPrefix ? "Add action" : "Action";

            if (canAddAction)
            {
                menu.AddItem(new GUIContent(actionString), false, OnAddAction);
            }
            else
            {
                menu.AddDisabledItem(new GUIContent(actionString), false);
            }

            var actionMapString = includeAddPrefix ? "Add action map" : "Action map";

            menu.AddItem(new GUIContent(actionMapString), false, OnAddActionMap);
            menu.AddSeparator("");
            var bindingString   = includeAddPrefix ? "Add binding" : "Binding";
            var compositeString = includeAddPrefix ? "Add composite binding" : "Composite binding";

            if (canAddBinding)
            {
                menu.AddItem(new GUIContent(bindingString), false, OnAddBinding);
                menu.AddItem(new GUIContent(compositeString + "/2 dimensions"), false, OnAddCompositeBinding, 2);
                menu.AddItem(new GUIContent(compositeString + "/4 dimensions"), false, OnAddCompositeBinding, 4);
            }
            else
            {
                menu.AddDisabledItem(new GUIContent(bindingString), false);
                menu.AddDisabledItem(new GUIContent(compositeString), false);
            }
        }
Beispiel #4
0
        public void HandlePasteEvent()
        {
            var json     = EditorGUIUtility.systemCopyBuffer;
            var elements = json.Split(new[] { kInputAssetMarker }, StringSplitOptions.RemoveEmptyEntries);

            if (!json.StartsWith(kInputAssetMarker))
            {
                return;
            }
            for (var i = 0; i < elements.Length; i++)
            {
                var row = elements[i];

                if (IsRowOfType <ActionMapTreeItem>(ref row))
                {
                    var map = JsonUtility.FromJson <InputActionMap>(row);
                    InputActionSerializationHelpers.AddActionMapFromObject(m_Window.m_SerializedObject, map);
                    m_Window.Apply();
                    continue;
                }

                if (IsRowOfType <ActionTreeItem>(ref row))
                {
                    var action            = JsonUtility.FromJson <InputAction>(row);
                    var actionMap         = m_TreeView.GetSelectedActionMap();
                    var newActionProperty = InputActionSerializationHelpers.AddActionFromObject(action, actionMap.elementProperty);
                    m_Window.Apply();

                    while (i + 1 < elements.Length)
                    {
                        try
                        {
                            var nextRow = elements[i + 1];
                            if (!nextRow.StartsWith(typeof(BindingTreeItem).Name))
                            {
                                break;
                            }
                            nextRow = nextRow.Substring(typeof(BindingTreeItem).Name.Length);
                            var binding = JsonUtility.FromJson <InputBinding>(nextRow);
                            InputActionSerializationHelpers.AppendBindingFromObject(binding, newActionProperty, actionMap.elementProperty);
                            m_Window.Apply();
                            i++;
                        }
                        catch (ArgumentException e)
                        {
                            Debug.LogException(e);
                            break;
                        }
                    }
                    continue;
                }

                if (IsRowOfType <BindingTreeItem>(ref row) ||
                    IsRowOfType <CompositeGroupTreeItem>(ref row) ||
                    IsRowOfType <CompositeTreeItem>(ref row))
                {
                    var binding     = JsonUtility.FromJson <InputBinding>(row);
                    var selectedRow = m_TreeView.GetSelectedAction();
                    if (selectedRow == null)
                    {
                        EditorApplication.Beep();
                        continue;
                    }

                    var actionMap = m_TreeView.GetSelectedActionMap();
                    InputActionSerializationHelpers.AppendBindingFromObject(binding, selectedRow.elementProperty, actionMap.elementProperty);
                    m_Window.Apply();
                    continue;
                }
            }
        }
Beispiel #5
0
        private void HandlePasteEvent()
        {
            var copyBufferString = EditorGUIUtility.systemCopyBuffer;
            var elements         = copyBufferString.Split(new[] { k_InputAssetMarker }, StringSplitOptions.RemoveEmptyEntries);

            if (!copyBufferString.StartsWith(k_InputAssetMarker))
            {
                return;
            }
            SerializedProperty currentActionMapProperty = null;
            var selectedActionMap = m_TreeView.GetSelectedActionMap();

            if (selectedActionMap != null)
            {
                currentActionMapProperty = selectedActionMap.elementProperty;
            }
            for (var i = 0; i < elements.Length; i++)
            {
                var row = elements[i];

                if (IsRowOfType <ActionMapTreeItem>(ref row))
                {
                    if (m_SerializedObject == null)
                    {
                        throw new InvalidOperationException("Pasting action map is not a valid operation");
                    }

                    currentActionMapProperty = InputActionSerializationHelpers.AddActionMapFromObject(m_SerializedObject, GetParameterDictionary(row));
                    m_Apply();
                    continue;
                }

                if (IsRowOfType <ActionTreeItem>(ref row))
                {
                    var newActionProperty = InputActionSerializationHelpers.AddActionFromObject(GetParameterDictionary(row), currentActionMapProperty);

                    while (i + 1 < elements.Length)
                    {
                        try
                        {
                            var nextRow = elements[i + 1];
                            if (nextRow.StartsWith(typeof(BindingTreeItem).Name))
                            {
                                nextRow = nextRow.Substring(typeof(BindingTreeItem).Name.Length);
                            }
                            else if (nextRow.StartsWith(typeof(CompositeGroupTreeItem).Name))
                            {
                                nextRow = nextRow.Substring(typeof(CompositeGroupTreeItem).Name.Length);
                            }
                            else if (nextRow.StartsWith(typeof(CompositeTreeItem).Name))
                            {
                                nextRow = nextRow.Substring(typeof(CompositeTreeItem).Name.Length);
                            }
                            else
                            {
                                break;
                            }
                            InputActionSerializationHelpers.AppendBindingFromObject(GetParameterDictionary(nextRow), newActionProperty, currentActionMapProperty);
                            i++;
                        }
                        catch (ArgumentException e)
                        {
                            Debug.LogException(e);
                            break;
                        }
                    }
                    m_Apply();
                    continue;
                }

                if (IsRowOfType <BindingTreeItem>(ref row) ||
                    IsRowOfType <CompositeGroupTreeItem>(ref row) ||
                    IsRowOfType <CompositeTreeItem>(ref row))
                {
                    var selectedRow = m_TreeView.GetSelectedAction();
                    if (selectedRow == null)
                    {
                        EditorApplication.Beep();
                        continue;
                    }

                    selectedRow.AppendBindingFromObject(GetParameterDictionary(row));
                    m_Apply();
                    continue;
                }
            }
        }