コード例 #1
0
ファイル: InputAction.cs プロジェクト: yebata/InputSystem
        public void RemoveBindingOverride(InputBindingOverride bindingOverride)
        {
            var undoBindingOverride = bindingOverride;

            undoBindingOverride.binding = null;

            // Simply apply but with a null binding.
            ApplyBindingOverride(undoBindingOverride);
        }
コード例 #2
0
ファイル: InputAction.cs プロジェクト: yebata/InputSystem
        // Find the binding tha tthe given override addresses.
        // Return -1 if no corresponding binding is found.
        private int FindBindingIndexForOverride(InputBindingOverride bindingOverride)
        {
            var group     = bindingOverride.group;
            var haveGroup = !string.IsNullOrEmpty(group);

            if (m_BindingsCount == 1)
            {
                // Simple case where we have only a single binding on the action.

                if (!haveGroup ||
                    string.Compare(m_Bindings[m_BindingsStartIndex].group, group,
                                   StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    return(0);
                }
            }
            else if (m_BindingsCount > 1)
            {
                // Trickier case where we need to select from a set of bindings.

                if (!haveGroup)
                {
                    // Group is required to disambiguate.
                    throw new InvalidOperationException(
                              string.Format(
                                  "Action {0} has multiple bindings; overriding binding requires the use of binding groups so the action knows which binding to override. Set 'group' property on InputBindingOverride.",
                                  this));
                }

                int groupStringLength;
                var indexInGroup        = bindingOverride.GetIndexInGroup(out groupStringLength);
                var currentIndexInGroup = 0;

                for (var i = 0; i < m_BindingsCount; ++i)
                {
                    if (string.Compare(m_Bindings[m_BindingsStartIndex + i].group, 0, group, 0, groupStringLength, true) == 0)
                    {
                        if (currentIndexInGroup == indexInGroup)
                        {
                            return(i);
                        }

                        ++currentIndexInGroup;
                    }
                }
            }

            return(-1);
        }
コード例 #3
0
ファイル: InputAction.cs プロジェクト: yebata/InputSystem
        // Apply the given override to the action.
        //
        // NOTE: Ignores the action name in the override.
        // NOTE: Action must be disabled while applying overrides.
        // NOTE: If there's already an override on the respective binding, replaces the override.
        public void ApplyBindingOverride(InputBindingOverride bindingOverride)
        {
            if (enabled)
            {
                throw new InvalidOperationException(
                          string.Format("Cannot change overrides on action '{0}' while the action is enabled", this));
            }

            if (bindingOverride.binding == string.Empty)
            {
                bindingOverride.binding = null;
            }

            var bindingIndex = FindBindingIndexForOverride(bindingOverride);

            if (bindingIndex == -1)
            {
                return;
            }

            m_Bindings[m_BindingsStartIndex + bindingIndex].overridePath = bindingOverride.binding;
        }