private IEnumerator StartListeningDelayed(int index, ControllerMap keyboardMap, ControllerMap mouseMap, int actionElementMapToReplaceId)
        {
            // Don't allow a binding for a short period of time after input field is activated
            // to prevent button bound to UI Submit from binding instantly when input field is activated.
            yield return(new WaitForSeconds(0.1f));

            // Begin listening for input on both keyboard and mouse at the same time

            inputMapper_keyboard.Start(
                new InputMapper.Context()
            {
                actionId                  = rows[index].action.id,
                controllerMap             = keyboardMap,
                actionRange               = rows[index].actionRange,
                actionElementMapToReplace = keyboardMap.GetElementMap(actionElementMapToReplaceId)
            }
                );

            inputMapper_mouse.Start(
                new InputMapper.Context()
            {
                actionId                  = rows[index].action.id,
                controllerMap             = mouseMap,
                actionRange               = rows[index].actionRange,
                actionElementMapToReplace = mouseMap.GetElementMap(actionElementMapToReplaceId)
            }
                );

            // Disable the UI Controller Maps while listening to prevent UI control and submissions.
            player.controllers.maps.SetMapsEnabled(false, uiCategory);

            // Update the UI text
            statusUIText.text = "Listening...";
        }
        // Event Handlers

        // Called by the input field UI Button when pressed
        private void OnInputFieldClicked(int index, int actionElementMapToReplaceId)
        {
            if (index < 0 || index >= rows.Count)
            {
                return;                                  // index out of range
            }
            ControllerMap keyboardMap = player.controllers.maps.GetMap(ControllerType.Keyboard, 0, category, layout);
            ControllerMap mouseMap    = player.controllers.maps.GetMap(ControllerType.Mouse, 0, category, layout);

            // Cannot replace a keyboard binding on a Mouse Map or vice versa
            // Replacement cross device has to be done by removing the other
            // binding manually after input is mapped.
            // Determine which map the replacement binding exists on and store that information.
            ControllerMap controllerMapWithReplacement;

            // Determine if the replacement is on the keyboard or mouse map
            if (keyboardMap.ContainsElementMap(actionElementMapToReplaceId))
            {
                controllerMapWithReplacement = keyboardMap;
            }
            else if (mouseMap.ContainsElementMap(actionElementMapToReplaceId))
            {
                controllerMapWithReplacement = mouseMap;
            }
            else
            {
                controllerMapWithReplacement = null;  // not a replacement
            }
            // Store the information about the replacement if any
            _replaceTargetMapping = new TargetMapping()
            {
                actionElementMapId = actionElementMapToReplaceId,
                controllerMap      = controllerMapWithReplacement
            };

            // Begin listening for input on both keyboard and mouse at the same time

            inputMapper_keyboard.Start(
                new InputMapper.Context()
            {
                actionId                  = rows[index].action.id,
                controllerMap             = keyboardMap,
                actionRange               = rows[index].actionRange,
                actionElementMapToReplace = keyboardMap.GetElementMap(actionElementMapToReplaceId)
            }
                );

            inputMapper_mouse.Start(
                new InputMapper.Context()
            {
                actionId                  = rows[index].action.id,
                controllerMap             = mouseMap,
                actionRange               = rows[index].actionRange,
                actionElementMapToReplace = mouseMap.GetElementMap(actionElementMapToReplaceId)
            }
                );

            statusUIText.text = "Listening...";
        }
Esempio n. 3
0
        private void OnInputFieldClicked(int index, int actionElementMapToReplaceId, ControllerMap map)
        {
            if (index < 0 || index >= Buttons.Count)
            {
                return;                                      // index out of range
            }
            // Begin listening for input
            InputMapper.Start(
                new InputMapper.Context()
            {
                actionId                  = Buttons[index].InputAction.id,
                controllerMap             = map,
                actionRange               = Buttons[index].AxisRange,
                actionElementMapToReplace = map.GetElementMap(actionElementMapToReplaceId)
            });

            // SHOW A UI TO TELL WE'RE LISTENING
        }
Esempio n. 4
0
        private void CheckMappingConflictAndConfirm()
        {
            if (!base.enabled)
            {
                return;
            }
            this._pollInput = false;
            bool   flag  = false;
            bool   flag2 = false;
            string text  = string.Empty;

            foreach (ElementAssignmentConflictInfo elementAssignmentConflictInfo in ReInput.controllers.conflictChecking.ElementAssignmentConflicts(this._entry.ToElementAssignmentConflictCheck()))
            {
                flag = true;
                ControllerMap controllerMap = Input.player.controllers.maps.GetAllMaps(elementAssignmentConflictInfo.controllerType).First <ControllerMap>();
                if (controllerMap != null)
                {
                    ActionElementMap elementMap = controllerMap.GetElementMap(elementAssignmentConflictInfo.elementMapId);
                    if (elementMap != null)
                    {
                        int actionId = elementMap.actionId;
                        if (this._entry.actionId == actionId)
                        {
                            this.Cancel();
                            return;
                        }
                        InputAction action = ReInput.mapping.GetAction(actionId);
                        string      text2  = action.descriptiveName.IfNullOrEmpty(action.name);
                        text2 = UiTranslationDatabase.TranslateKey(text2.ToUpper(), text2, true);
                        if (!elementAssignmentConflictInfo.isUserAssignable || !action.userAssignable)
                        {
                            flag2 = true;
                            text  = text2;
                            break;
                        }
                        text = text + text2 + ", ";
                    }
                }
            }
            if (flag)
            {
                if (flag2)
                {
                    string message = this._entry.elementName + " is already in use and is protected from reassignment. You cannot remove the protected assignment, but you can still assign the action to this element. If you do so, the element will trigger multiple actions when activated.";
                    Debug.Log(message);
                    this.CancelConflictingMapping();
                }
                else
                {
                    string message2 = this._entry.elementName + " is already in use. You may replace the other conflicting assignments, add this assignment anyway which will leave multiple actions assigned to this element, or cancel this assignment.";
                    Debug.Log(message2);
                    text = text.TrimEnd(new char[]
                    {
                        ' ',
                        ','
                    });
                    this.ConfirmKeepingConflicts();
                }
                this._nextChangeTimer = Time.realtimeSinceStartup + this._interChangeDelay;
            }
            else
            {
                this.Confirm(InputMappingAction.ConflictResolution.DoNothing);
            }
        }