////TODO: add method to add an existing InputAction to a map public static InputAction AddAction(this InputActionMap map, string name, InputActionType type = default, string binding = null, string interactions = null, string processors = null, string groups = null, string expectedControlLayout = null) { if (map == null) { throw new ArgumentNullException(nameof(map)); } if (string.IsNullOrEmpty(name)) { throw new ArgumentException("Action must have name", nameof(name)); } if (map.enabled) { throw new InvalidOperationException( $"Cannot add action '{name}' to map '{map}' while it the map is enabled"); } if (map.FindAction(name) != null) { throw new InvalidOperationException( $"Cannot add action with duplicate name '{name}' to set '{map.name}'"); } // Append action to array. var action = new InputAction(name, type) { expectedControlType = expectedControlLayout }; action.GenerateId(); ArrayHelpers.Append(ref map.m_Actions, action); action.m_ActionMap = map; ////TODO: make sure we blast out existing action map state // Add binding, if supplied. if (!string.IsNullOrEmpty(binding)) { action.AddBinding(binding, interactions: interactions, processors: processors, groups: groups); } else { if (!string.IsNullOrEmpty(groups)) { throw new ArgumentException( $"No binding path was specified for action '{action}' but groups was specified ('{groups}'); cannot apply groups without binding", nameof(groups)); } // If no binding has been supplied but there are interactions and processors, they go on the action itself. action.m_Interactions = interactions; action.m_Processors = processors; } return(action); }
public CompositeSyntax With(string name, string binding, string groups = null) { ////TODO: check whether non-composite bindings have been added in-between int bindingIndex; if (m_Action != null) { bindingIndex = m_Action.AddBinding(path: binding, groups: groups) .m_BindingIndex; } else { bindingIndex = m_ActionMap.AddBinding(path: binding, groups: groups) .m_BindingIndex; } m_ActionMap.m_Bindings[bindingIndex].name = name; m_ActionMap.m_Bindings[bindingIndex].isPartOfComposite = true; return(this); }