Exemple #1
0
        private void RedrawUI(ControllerMap map)
        {
            // Update each button label with the currently mapped element identifier
            for (int i = 0; i < Buttons.Count; i++)
            {
                Template.InputButtonTemplate template = Buttons[i];
                InputAction action = Buttons[i].InputAction;

                string name = string.Empty;
                int    actionElementMapId = -1;

                // Find the first ActionElementMap that maps to this action and is compatible with this field type
                foreach (var actionElementMap in map.ElementMapsWithAction(action.id))
                {
                    Debug.Log(actionElementMap.actionDescriptiveName + " | " + actionElementMap.controllerMap.controllerType.ToString());
                    if (actionElementMap.controllerMap.controllerType == ControllerType.Keyboard)
                    {
                        template.IsKeyboard = true;
                    }

                    if (actionElementMap.ShowInField(template.AxisRange))
                    {
                        name = actionElementMap.elementIdentifierName;
                        actionElementMapId = actionElementMap.id;
                        break;
                    }
                }

                if (map.controllerType == ControllerType.Keyboard && template.IsKeyboard)
                {
                    // Set the label for the button
                    template.RemapButtonText.SetText(name);

                    // Set the field button callback
                    template.RemapButton.onClick.RemoveAllListeners(); // clear all events
                    int index = i;                                     // copy the variable for closer
                    template.RemapButton.onClick.AddListener(() => OnInputFieldClicked(index, actionElementMapId, map));
                }
                else if (map.controllerType == ControllerType.Mouse && !template.IsKeyboard)
                {
                    template.transform.SetParent(MouseControlContent);

                    // Set the label for the button
                    template.RemapButtonText.SetText(name);

                    // Set the field button callback
                    template.RemapButton.onClick.RemoveAllListeners(); // clear all events
                    int index = i;                                     // copy the variable for closer
                    template.RemapButton.onClick.AddListener(() => OnInputFieldClicked(index, actionElementMapId, map));
                }
            }
        }
        private void RedrawUI()
        {
            // Update joystick name in UI
            controllerNameUIText.text = "Keyboard/Mouse";

            // Update each button label with the currently mapped element identifier
            for (int i = 0; i < rows.Count; i++)
            {
                Row         row    = rows[i];
                InputAction action = rows[i].action;

                string name = string.Empty;
                int    actionElementMapId = -1;

                // Find the first ActionElementMap that maps to this Action and is compatible with this field type
                for (int j = 0; j < 2; j++)
                {
                    // Search the Keyboard Map first, then the Mouse Map
                    ControllerType controllerType = j == 0 ? ControllerType.Keyboard : ControllerType.Mouse;
                    ControllerMap  controllerMap  = player.controllers.maps.GetMap(controllerType, 0, category, layout);
                    foreach (var actionElementMap in controllerMap.ElementMapsWithAction(action.id))
                    {
                        if (actionElementMap.ShowInField(row.actionRange))
                        {
                            name = actionElementMap.elementIdentifierName;
                            actionElementMapId = actionElementMap.id;
                            break;
                        }
                    }

                    if (actionElementMapId >= 0)
                    {
                        break;                          // found one
                    }
                }

                // Set the label in the field button
                row.text.text = name;

                // Set the field button callback
                row.button.onClick.RemoveAllListeners(); // clear the button event listeners first
                int index = i;                           // copy variable for closure
                row.button.onClick.AddListener(() => OnInputFieldClicked(index, actionElementMapId));
            }
        }