Example #1
0
        // todo: add deadzone support (trello card exists)
        public float GetAxis(string binding)
        {
            float realAxis = UnityEngine.Input.GetAxis(GetKeyCodeString(binding));

            KeyCodeValue keyCodeValue = GetKeyCodeValue(binding);

            if (keyCodeValue.AxisDirection == KeyCodeValue.AxisDirections.Positive)
            {
                if (realAxis > keyCodeValue.DeadZone)
                {
                    return(realAxis);
                }
            }
            else
            {
                // ironically, we want this to be a positive number
                float negativeAxis = -realAxis;

                if (negativeAxis > keyCodeValue.DeadZone)
                {
                    return(negativeAxis);
                }
            }
            return(0f);
        }
Example #2
0
        public bool IsKeyHeld(string binding)
        {
            KeyCodeValue keyCodeValue = GetKeyCodeValue(binding)
                                        ?? throw new InvalidConfigurationException <GamepadBindings>($"Unable to find a keybinding for {binding}");

            // read it as a button
            bool isDown = UnityEngine.Input.GetButton(keyCodeValue.KeyCode);

            if (!isDown)
            {
                // if that returns false, try as an axis
                isDown = UnityEngine.Input.GetAxis(keyCodeValue.KeyCode) > axisButtonInputThreshold;
            }
            return(isDown);
        }
Example #3
0
        // Pulls the bound value for the gamepad input.  Note - Only one binding will be used for gamepad inputs
        private bool TryGetKeyBinding(string binding, out KeyCodeValue keyCodeValues)
        {
            if (GetKeyBindings().Bindings.TryGetValue(binding, out IEnumerable <KeyCodeValue> values))
            {
                if (values.Count() > 1)
                {
                    UnityEngine.Debug.LogWarning($"Warning!  Multiple keys are bound to binding '{binding}'.  The first one will be used" +
                                                 "and the rest will be ignored.");
                }

                keyCodeValues = values.First();
                return(true);
            }
            keyCodeValues = null;
            return(false);
        }
Example #4
0
        public bool IsKeyHit(string binding)
        {
            KeyCodeValue keyCodeValue = GetKeyCodeValue(binding)
                                        ?? throw new InvalidConfigurationException <GamepadBindings>($"Unable to find a keybinding for {binding}");

            if (keyCodeValue.ReadAsAxis)
            {
                // if the button was previously not pressed and is now pressed
                bool wasHeld = axisDictionary[binding];
                if (!wasHeld)
                {
                    return(GetAxis(binding) > axisButtonInputThreshold);
                }
                return(false);
            }

            return(UnityEngine.Input.GetButtonDown(GetKeyCodeString(binding)));
        }