Exemple #1
0
        private KeyCode GetKeyForAxis(string axis, KBMInputAxisKeyType keyType)
        {
            if (InputMap.AxisMappings.TryGetValue(axis, out var mapping))
            {
                switch (keyType)
                {
                case KBMInputAxisKeyType.PrimaryPositive:
                    return((KeyCode)mapping.PrimaryPositive);

                case KBMInputAxisKeyType.PrimaryNegative:
                    return((KeyCode)mapping.PrimaryNegative);

                case KBMInputAxisKeyType.SecondaryPositive:
                    return((KeyCode)mapping.SecondaryPositive);

                case KBMInputAxisKeyType.SecondaryNegative:
                    return((KeyCode)mapping.SecondaryNegative);

                default:
                    throw new KeyNotFoundException();
                }
            }
            else
            {
                Debug.LogWarning($"Couldn't find a mapping for axis \"{axis}\"");
                return(KeyCode.None);
            }
        }
Exemple #2
0
        private void SetKeyOnAxis(KeyCode key, string axis, KBMInputAxisKeyType keyType)
        {
            if (InputMap.AxisMappings.TryGetValue(axis, out var mapping))
            {
                switch (keyType)
                {
                case KBMInputAxisKeyType.PrimaryPositive:
                    mapping.PrimaryPositive = (int)key;
                    break;

                case KBMInputAxisKeyType.PrimaryNegative:
                    mapping.PrimaryNegative = (int)key;
                    break;

                case KBMInputAxisKeyType.SecondaryPositive:
                    mapping.SecondaryPositive = (int)key;
                    break;

                case KBMInputAxisKeyType.SecondaryNegative:
                    mapping.SecondaryNegative = (int)key;
                    break;

                default:
                    throw new KeyNotFoundException();
                }

                InputMap.AxisMappings[axis] = mapping; //value types, folks!
            }
            else
            {
                Debug.LogWarning($"Couldn't find a mapping for axis \"{axis}\"");
            }
        }
Exemple #3
0
        //open the "change mapping" window and do all that (for axis keys)
        private void HandleAxisKeyRemappingStarted(string axisName, KBMInputAxisKeyType keyType, Button button)
        {
            string  displayName = $"{Sub.Replace(axisName, "CFG_MAPPINGS")} {((keyType == KBMInputAxisKeyType.PrimaryPositive || keyType == KBMInputAxisKeyType.SecondaryPositive) ? Sub.Replace("+", "EXPLICITKBMINPUT") : Sub.Replace("-", "EXPLICITKBMINPUT"))}";
            KeyCode oldKey      = GetKeyForAxis(axisName, keyType);

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

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