public static InputAction AddAction(this InputActionMap map, string name, string binding = null, string interactions = null, string groups = null, string expectedControlLayout = null) { if (map == null) { throw new ArgumentNullException("map"); } if (string.IsNullOrEmpty(name)) { throw new ArgumentException("Action must have name", "name"); } if (map.enabled) { throw new InvalidOperationException( string.Format("Cannot add action '{0}' to map '{1}' while it the map is enabled", name, map)); } if (map.TryGetAction(name) != null) { throw new InvalidOperationException( string.Format("Cannot add action with duplicate name '{0}' to set '{1}'", name, map.name)); } // Append action to array. var action = new InputAction(name); action.expectedControlLayout = expectedControlLayout; 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.AppendBinding(binding, interactions: interactions, groups: groups); } return(action); }
public CompositeSyntax With(string name, string binding, string interactions = null, string groups = null) { ////TODO: check whether non-composite bindings have been added in-between int bindingIndex; if (m_Action != null) { bindingIndex = m_Action.AppendBinding(path: binding, interactions: interactions, groups: groups) .m_BindingIndex; } else { bindingIndex = m_ActionMap.AppendBinding(path: binding, interactions: interactions, groups: groups) .m_BindingIndex; } m_ActionMap.m_Bindings[bindingIndex].name = name; m_ActionMap.m_Bindings[bindingIndex].isPartOfComposite = true; return(this); }