Beispiel #1
0
    private bool IsValueInDeadzone(float value, GamepadAxisInfo info)
    {
        int multiplier = value >= info.UnpressedValue ? 1 : -1;

        //Make sure that we don't get false positives, due to the deadzone there is on buttons
        if (multiplier < 0)
        {
            return(value > info.UnpressedValue + (multiplier * info.DeadZoneOffset));
        }
        return(value < info.UnpressedValue + (multiplier * info.DeadZoneOffset));
    }
Beispiel #2
0
    public bool GetAxisAsButtonUp(GamepadAxis axis, int playerNumber, PositiveNegativeAxis whichDirection)
    {
        var mapping = this.AxisToButtonStates.Where(state => state.BelongingMapping == this.PlayerMappings[playerNumber] && state.Axis == axis && state.DoesAxisMatter == whichDirection).ToList();

        if (mapping.Count != 0)
        {
            return(!mapping[0].PressedInCurrentFrame && mapping[0].PressedLastFrame);
        }
        else
        {
            //Add to list (Basically "subscribe" to it
            var newAxisState = new AxisState()
            {
                BelongingMapping = this.PlayerMappings[playerNumber], Axis = axis, DoesAxisMatter = whichDirection
            };

            if (this.PlayerMappings[playerNumber].OverridesAxisReading)
            {
                float value = this.PlayerMappings[playerNumber].OverrideAxisReading(axis);
                newAxisState.PressedInCurrentFrame = value != 0;
            }
            else
            {
                GamepadAxisInfo info  = this.PlayerMappings[playerNumber].AxisBindingLookupTable[axis];
                float           value = Input.GetAxisRaw(info.AxisName);

                int multiplier = whichDirection == PositiveNegativeAxis.Negative ? -1 : 1;
                if (multiplier < 0)
                {
                    newAxisState.PressedInCurrentFrame = value < info.UnpressedValue + (multiplier * info.DeadZoneOffset);
                }
                else
                {
                    newAxisState.PressedInCurrentFrame = value > info.UnpressedValue + (multiplier * info.DeadZoneOffset);
                }
            }
            //newAxisState.PressedInCurrentFrame = value > info.UnpressedValue + (multiplier * info.DeadZoneOffset);
            this.AxisToButtonStates.Add(newAxisState);
            return(!newAxisState.PressedInCurrentFrame && newAxisState.PressedLastFrame);
        }
    }
Beispiel #3
0
    /// <summary>
    /// Mimics an axis to act like a button. This is useful for triggers on controllers like PS4 or Xbox, where you want the triggers to be a button, and not an analog value
    /// </summary>
    /// <param name="axis"></param>
    /// <param name="playerNumber"></param>
    /// <returns></returns>
    public bool GetAxisAsButtonDown(GamepadAxis axis, int playerNumber)
    {
        var mapping = this.AxisToButtonStates.Where(state => state.BelongingMapping == this.PlayerMappings[playerNumber] && state.Axis == axis && state.DoesAxisMatter == PositiveNegativeAxis.Indifferent).ToList();

        if (mapping.Count != 0)
        {
            return(mapping[0].PressedInCurrentFrame && !mapping[0].PressedLastFrame);
        }
        else
        {
            //Add to list (Basically "subscribe" to it)
            var newAxisState = new AxisState()
            {
                BelongingMapping = this.PlayerMappings[playerNumber], Axis = axis
            };
            if (this.PlayerMappings[playerNumber].OverridesAxisReading)
            {
                float value = this.PlayerMappings[playerNumber].OverrideAxisReading(axis);
                newAxisState.PressedInCurrentFrame = value != 0;
            }
            else
            {
                GamepadAxisInfo info  = this.PlayerMappings[playerNumber].AxisBindingLookupTable[axis];
                float           value = this.GetAxisValue(axis, playerNumber);

                int multiplier = value >= info.UnpressedValue ? 1 : -1;
                if (multiplier < 0)
                {
                    newAxisState.PressedInCurrentFrame = value < info.UnpressedValue + (multiplier * info.DeadZoneOffset);
                }
                else
                {
                    newAxisState.PressedInCurrentFrame = value > info.UnpressedValue + (multiplier * info.DeadZoneOffset);
                }
            }
            this.AxisToButtonStates.Add(newAxisState);
            return(newAxisState.PressedInCurrentFrame);
        }
    }