/// <summary> /// Set the <see cref="InputBinding.name"/> of the binding. /// </summary> /// <param name="name">Name for the binding.</param> /// <returns>The same binding syntax for further configuration.</returns> /// <seealso cref="InputBinding.name"/> /// <seealso cref="AddBinding"/> public BindingSyntax WithName(string name) { m_ActionMap.m_Bindings[m_BindingIndex].name = name; m_ActionMap.ClearPerActionCachedBindingData(); m_ActionMap.LazyResolveBindings(); return(this); }
private static int AddBindingInternal(InputActionMap map, InputBinding binding) { Debug.Assert(map != null); // Make sure the binding has an ID. if (string.IsNullOrEmpty(binding.m_Id)) { binding.GenerateId(); } // Append to bindings in set. var bindingIndex = ArrayHelpers.Append(ref map.m_Bindings, binding); // Invalidate per-action binding sets so that this gets refreshed if // anyone queries it. map.ClearPerActionCachedBindingData(); // Make sure bindings get re-resolved. map.LazyResolveBindings(); // If we're looking at a singleton action, make sure m_Bindings is up to date just // in case the action gets serialized. if (map.m_SingletonAction != null) { map.m_SingletonAction.m_SingletonActionBindings = map.m_Bindings; } return(bindingIndex); }
public static void ApplyBindingOverride(this InputActionMap actionMap, int bindingIndex, InputBinding bindingOverride) { if (actionMap == null) { throw new ArgumentNullException(nameof(actionMap)); } var bindingsCount = actionMap.m_Bindings?.Length ?? 0; if (bindingIndex < 0 || bindingIndex >= bindingsCount) { throw new ArgumentOutOfRangeException(nameof(bindingIndex), $"Cannot apply override to binding at index {bindingIndex} in map '{actionMap}' with only {bindingsCount} bindings"); } actionMap.m_Bindings[bindingIndex].overridePath = bindingOverride.overridePath; actionMap.m_Bindings[bindingIndex].overrideInteractions = bindingOverride.overrideInteractions; actionMap.LazyResolveBindings(); }
/// <summary> /// Apply the given binding override to all bindings in the map that are matched by the override. /// </summary> /// <param name="actionMap"></param> /// <param name="bindingOverride"></param> /// <returns>The number of bindings overridden in the given map.</returns> /// <exception cref="ArgumentNullException"><paramref name="actionMap"/> is <c>null</c>.</exception> /// <exception cref="InvalidOperationException"><paramref name="actionMap"/> is currently enabled.</exception> /// <remarks> /// </remarks> public static int ApplyBindingOverride(this InputActionMap actionMap, InputBinding bindingOverride) { if (actionMap == null) { throw new ArgumentNullException(nameof(actionMap)); } actionMap.ThrowIfModifyingBindingsIsNotAllowed(); var bindings = actionMap.m_Bindings; if (bindings == null) { return(0); } // Go through all bindings in the map and match them to the override. var bindingCount = bindings.Length; var matchCount = 0; for (var i = 0; i < bindingCount; ++i) { if (!bindingOverride.Matches(ref bindings[i])) { continue; } // Set overrides on binding. bindings[i].overridePath = bindingOverride.overridePath; bindings[i].overrideInteractions = bindingOverride.overrideInteractions; ++matchCount; } if (matchCount > 0) { actionMap.LazyResolveBindings(); } return(matchCount); }