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();

            // 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);
        }
Beispiel #2
0
            public BindingSyntax WithGroups(string groups)
            {
                if (string.IsNullOrEmpty(groups))
                {
                    return(this);
                }

                // Join with existing group, if any.
                var currentGroups = m_ActionMap.m_Bindings[m_BindingIndex].groups;

                if (!string.IsNullOrEmpty(currentGroups))
                {
                    groups = string.Join(InputBinding.kSeparatorString, new[] { currentGroups, groups });
                }

                // Set groups on binding.
                m_ActionMap.m_Bindings[m_BindingIndex].groups = groups;
                m_ActionMap.ClearPerActionCachedBindingData();

                return(this);
            }
Beispiel #3
0
        public static void ApplyBindingOverride(this InputActionMap actionMap, int bindingIndex, InputBinding bindingOverride)
        {
            if (actionMap == null)
            {
                throw new ArgumentNullException("actionMap");
            }
            var bindingsCount = actionMap.m_Bindings != null ? actionMap.m_Bindings.Length : 0;

            if (bindingIndex < 0 || bindingIndex >= bindingsCount)
            {
                throw new ArgumentOutOfRangeException(
                          string.Format("Cannot apply override to binding at index {0} in map '{1}' with only {2} bindings",
                                        bindingIndex, actionMap, bindingsCount), "bindingIndex");
            }

            actionMap.m_Bindings[bindingIndex].overridePath         = bindingOverride.overridePath;
            actionMap.m_Bindings[bindingIndex].overrideInteractions = bindingOverride.overrideInteractions;
            actionMap.ClearPerActionCachedBindingData();
        }
Beispiel #4
0
        /// <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("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.ClearPerActionCachedBindingData();
            }

            return(matchCount);
        }