Exemple #1
0
    /// <summary>
    /// Returns the value of the specified joystick axis
    /// </summary>
    /// <param name="btn"></param>
    /// <returns></returns>
    public static float GetJoystickAxis(JOYSTICK joy, AXIS axis)
    {
        string input = PAD_PREFIX;

        switch (joy)
        {
        case JOYSTICK.L:
            input += LEFT_JOYSTICK_PREFIX;
            break;

        case JOYSTICK.R:
            input += RIGHT_JOYSTICK_PREFIX;
            break;
        }

        switch (axis)
        {
        case AXIS.X:
            input += X;
            break;

        case AXIS.Y:
            input += Y;
            break;
        }

        return(Input.GetAxisRaw(input));
    }
/******************************************************
 * Function: GetAxis
 * Parameters: 
 *		whichPlayer - Players ONE through FOUR
 *		whichJoystick - Left, Right, or DPAD
 *		whichAxis - X or Y
 * Return:
 *		Returns the float value of the axis desired for
 *		the specific player and joystick 
******************************************************/
	public static float GetAxis(PLAYER_NUMBER whichPlayer, JOYSTICK whichJoystick, AXIS whichAxis)
	{
		float axisValue = 0.0f;

		string inputToCheck = "";

#if UNITY_ANDROID
		if (whichJoystick != JOYSTICK.LEFT)
			inputToCheck += "A_";
#endif

		inputToCheck += "P" + ((int)whichPlayer).ToString() + "_";

		switch (whichJoystick)
		{
			case JOYSTICK.LEFT:
				inputToCheck += "LeftStick_";
				break;
			case JOYSTICK.RIGHT:
				inputToCheck += "RightStick_";
				break;
			case JOYSTICK.DPAD:
				inputToCheck += "DPad_";
				break;
			default:
				break;
		}

		switch (whichAxis)
		{
			case AXIS.X:
				inputToCheck += "X";
				break;
			case AXIS.Y:
				inputToCheck += "Y";
				break;
			default:
				return 0.0f;
		}

		axisValue = Input.GetAxis(inputToCheck);

		return axisValue;
	}
Exemple #3
0
 bool CheckButton(JOYSTICK btn)
 {
     //int btnChk = (int)btn;
     //Debug.Print("btn[" + btnChk + "];" + _btns[btnChk]);
     return(_btns[(int)btn] && !_btnsLast[(int)btn]);
 }
Exemple #4
0
    /// <summary>
    /// Returns true on the frame the axis passes the trigger value
    /// Use negative values for negative axis
    /// Ex : left means the trigger value is -0.5f on X Axis
    /// </summary>
    /// <param name="btn"></param>
    /// <returns></returns>
    public static bool GetJoystickAxisDown(JOYSTICK joy, AXIS axis, float triggerValue)
    {
        bool value = false;

        string input = PAD_PREFIX;

        switch (joy)
        {
        case JOYSTICK.L:
            input += LEFT_JOYSTICK_PREFIX;
            break;

        case JOYSTICK.R:
            input += RIGHT_JOYSTICK_PREFIX;
            break;
        }

        switch (axis)
        {
        case AXIS.X:
            input += X;
            break;

        case AXIS.Y:
            input += Y;
            break;
        }

        bool test = false;

        if (triggerValue < 0)
        {
            test   = Input.GetAxis(input) <= triggerValue;
            input += "_Neg";
        }
        else
        {
            test   = Input.GetAxis(input) >= triggerValue;
            input += "_Pos";
        }

        if (test)
        {
            if (!_axisValues.ContainsKey(input))
            {
                _axisValues.Add(input, true);
                value = true;
            }
            else
            {
                value = !_axisValues[input];
                _axisValues[input] = true;
            }
        }
        else
        {
            if (!_axisValues.ContainsKey(input))
            {
                _axisValues.Add(input, false);
            }
            else
            {
                _axisValues[input] = false;
            }

            value = false;
        }

        return(value);
    }