public static InputAction AddAction(this InputActionMap map, string name, 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) { expectedControlLayout = 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 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.AddBinding(path: binding, interactions: interactions, groups: groups) .m_BindingIndex; } else { bindingIndex = m_ActionMap.AddBinding(path: binding, interactions: interactions, groups: groups) .m_BindingIndex; } m_ActionMap.m_Bindings[bindingIndex].name = name; m_ActionMap.m_Bindings[bindingIndex].isPartOfComposite = true; return(this); }
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.AddBinding(binding, interactions: interactions, groups: groups); } return(action); }