Пример #1
0
        private KeyCode GetKeyForButton(string button, KBMInputButtonKeyType keyType)
        {
            if (InputMap.ButtonMappings.TryGetValue(button, out var mapping))
            {
                switch (keyType)
                {
                case KBMInputButtonKeyType.Primary:
                    return((KeyCode)mapping.Primary);

                case KBMInputButtonKeyType.Secondary:
                    return((KeyCode)mapping.Secondary);

                case KBMInputButtonKeyType.Tertiary:
                    return((KeyCode)mapping.Tertiary);

                default:
                    throw new KeyNotFoundException();
                }
            }
            else
            {
                Debug.LogWarning($"Couldn't find a mapping for button \"{button}\"");
                return(KeyCode.None);
            }
        }
Пример #2
0
        private void SetKeyOnButton(KeyCode key, string button, KBMInputButtonKeyType keyType)
        {
            if (InputMap.ButtonMappings.TryGetValue(button, out var mapping))
            {
                switch (keyType)
                {
                case KBMInputButtonKeyType.Primary:
                    mapping.Primary = (int)key;
                    break;

                case KBMInputButtonKeyType.Secondary:
                    mapping.Secondary = (int)key;
                    break;

                case KBMInputButtonKeyType.Tertiary:
                    mapping.Tertiary = (int)key;
                    break;

                default:
                    throw new KeyNotFoundException();
                }

                InputMap.ButtonMappings[button] = mapping; //value types, folks!
            }
            else
            {
                Debug.LogWarning($"Couldn't find a mapping for button \"{button}\"");
            }
        }
Пример #3
0
        //open the "change mapping" window and do all that (for button keys)
        private void HandleButtonKeyRemappingStarted(string buttonName, KBMInputButtonKeyType keyType, Button button)
        {
            string  displayName = Sub.Replace(buttonName, "CFG_MAPPINGS");
            KeyCode oldKey      = GetKeyForButton(buttonName, keyType);

            MappingModal.GetMapping(displayName, oldKey, (newKey) => {
                if (newKey.HasValue)
                {
                    // Debug.Log(newKey);

                    SetKeyOnButton(newKey.Value, buttonName, keyType);
                    button.GetComponentInChildren <Text>().text = InputModule.GetNameForKeyCode(newKey.Value);
                }
            });
        }