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.TryGetAction(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); }