Beispiel #1
0
    public static bool GetButtonUp(string buttonName)
    {
        STBAxis axis = FindAxis(buttonName);

        if (axis == null)
        {
            return(false);
        }

        if (instance.playerCount == 1)
        {
            for (int i = 0; i < 5; i++)
            {
                if (GetButtonUp(buttonName, i))
                {
                    return(true);
                }
            }
        }
        else
        {
            for (int i = 0; i < 4; i++)
            {
                if (!EffectPlayer(axis, i))
                {
                    continue;
                }
                if (GetButtonUp(buttonName, playerDevices[i]))
                {
                    return(true);
                }
            }
        }
        return(false);
    }
Beispiel #2
0
    public static float GetAxis(string axisName)
    {
        STBAxis axis = FindAxis(axisName);

        if (axis == null)
        {
            return(0f);
        }

        float value = 0f;

        for (int i = 0; i < 4; i++)
        {
            if (!EffectPlayer(axis, i))
            {
                continue;
            }

            float playerAxis = GetAxis(axisName, playerDevices[i]);
            if (axis.sumInputs)
            {
                value += playerAxis;
            }
            else
            {
                value = MaxAxis(value, playerAxis);
            }
        }

        value = Mathf.Clamp(value, -1f, 1f);
        return(value);
    }
Beispiel #3
0
 static bool EffectPlayer(STBAxis axis, int index)
 {
     if (!IsPlayerDeviceSet(index))
     {
         return(false);
     }
     if (axis.playerNum == PlayerNum.AllPlayer)
     {
         return(true);
     }
     if (axis.playerNum == (PlayerNum)index)
     {
         return(true);
     }
     return(false);
 }
Beispiel #4
0
    public static bool GetButton(string buttonName)
    {
        STBAxis axis = FindAxis(buttonName);

        if (axis == null)
        {
            return(false);
        }

        for (int i = 0; i < 4; i++)
        {
            if (!EffectPlayer(axis, i))
            {
                continue;
            }
            if (GetButton(buttonName, playerDevices[i]))
            {
                return(true);
            }
        }
        return(false);
    }
Beispiel #5
0
    public static bool GetButtonUp(string buttonName, int deviceNum)
    {
        STBAxis axis = FindAxis(buttonName);

        if (axis == null)
        {
            return(false);
        }

        InputDeviceType deviceType = GetDeviceType(deviceNum);

        switch (deviceType)
        {
        case InputDeviceType.KeyboardAndMouse:
            foreach (STBInputElement input in axis.inputs)
            {
                if (input.deviceType != InputDeviceType.KeyboardAndMouse)
                {
                    continue;
                }

                if (!string.IsNullOrEmpty(input.negativeButton))
                {
                    if (Input.GetKeyUp(input.negativeButton))
                    {
                        return(true);
                    }
                }
                if (!string.IsNullOrEmpty(input.positiveButton))
                {
                    if (Input.GetKeyUp(input.positiveButton))
                    {
                        return(true);
                    }
                }
            }
            break;

        default:
            foreach (STBInputElement input in axis.inputs)
            {
                if (input.deviceType != deviceType)
                {
                    continue;
                }

                if (!string.IsNullOrEmpty(input.negativeButton))
                {
                    if (GetJoystickButtonUp(input.negativeButton, deviceNum))
                    {
                        return(true);
                    }
                }
                if (!string.IsNullOrEmpty(input.positiveButton))
                {
                    if (GetJoystickButtonUp(input.positiveButton, deviceNum))
                    {
                        return(true);
                    }
                }
            }
            break;
        }
        return(false);
    }
Beispiel #6
0
    public static float GetAxis(string axisName, int deviceNum)
    {
        STBAxis axis = FindAxis(axisName);

        if (axis == null)
        {
            return(0f);
        }

        float           value      = 0f;
        InputDeviceType deviceType = GetDeviceType(deviceNum);

        switch (deviceType)
        {
        case InputDeviceType.KeyboardAndMouse:
            foreach (STBInputElement input in axis.inputs)
            {
                if (input.deviceType != InputDeviceType.KeyboardAndMouse)
                {
                    continue;
                }

                float keyAxis = 0f;
                if (!string.IsNullOrEmpty(input.negativeButton))
                {
                    if (Input.GetKey(input.negativeButton))
                    {
                        keyAxis -= 1f;
                    }
                }
                if (!string.IsNullOrEmpty(input.positiveButton))
                {
                    if (Input.GetKey(input.positiveButton))
                    {
                        keyAxis += 1f;
                    }
                }

                if (axis.sumInputs)
                {
                    value += keyAxis;
                }
                else
                {
                    value = MaxAxis(value, keyAxis);
                }
            }
            break;

        default:
            foreach (STBInputElement input in axis.inputs)
            {
                if (input.deviceType != deviceType)
                {
                    continue;
                }

                float joyAxis = GetJoystickAxis(input.axis, deviceNum);
                if (input.invert)
                {
                    joyAxis *= -1f;
                }
                if (!string.IsNullOrEmpty(input.negativeButton))
                {
                    if (GetJoystickButton(input.negativeButton, deviceNum))
                    {
                        joyAxis -= 1f;
                    }
                }
                if (!string.IsNullOrEmpty(input.positiveButton))
                {
                    if (GetJoystickButton(input.positiveButton, deviceNum))
                    {
                        joyAxis += 1f;
                    }
                }

                if (axis.sumInputs)
                {
                    value += joyAxis;
                }
                else
                {
                    value = MaxAxis(value, joyAxis);
                }
            }
            break;
        }

        value = Mathf.Clamp(value, -1f, 1f);
        return(value);
    }