Example #1
0
    void Update()
    {
        if (GamepadManager != null)
        {
            if (!IsRegistered)
            {
                SGHandshakeMsg handshake = new SGHandshakeMsg();
                SGID               = GamepadManager.MaxPlayers + LocalInputIndex;
                handshake.SGID     = SGID;
                handshake.DeviceId = Input.GetJoystickNames()[LocalInputIndex];
                GamepadManager.InjectGamepadHandshake(handshake);
                IsRegistered = true;
            }

            //Buttons 0-9
            for (b = 0; b < 10; b++)
            {
                button = Input.GetAxisRaw(PlayerStr + (LocalInputIndex + 1).ToString() + ButtonStr + b.ToString()) > 0;
                InputData.SetField("button " + b.ToString(), button);
            }

            //Axes (LeftX, LeftY, RightX, RightY, POVX, POVY, LeftTrigger, RightTrigger) 0-8 (indices 10-17)
            for (a = 0; a < 8; a++)
            {
                axis = Input.GetAxisRaw(PlayerStr + (LocalInputIndex + 1).ToString() + AxisStr + (a + 1).ToString());
                InputData.SetField("axis " + a.ToString(), axis);
            }

            UpdateMsg.SGID = SGID;
            UpdateMsg.Data = InputData;

            GamepadManager.InjectGamepadUpdate(UpdateMsg);
        }
    }
Example #2
0
    private void Start()
    {
        GamepadManager = FindObjectOfType <FyoApplication>();

        if (LocalInputIndex >= 0 && LocalInputIndex < 8)
        {
            //Allocate Buttons
            for (int b = 0; b < 10; b++)
            {
                InputData.AddField("button " + b.ToString(), false);
            }

            //Allocate Axes
            for (int a = 0; a < 8; a++)
            {
                InputData.AddField("axis " + (a + 1).ToString(), 0.0f);
            }
        }
        else
        {
            Debug.LogWarning("Local Input is not configured for a valid Local Gamepad");
        }

        if (InjectOnStart)
        {
            SGHandshakeMsg handshake = new SGHandshakeMsg();
            SGID               = GamepadManager.MaxPlayers + LocalInputIndex;
            handshake.SGID     = SGID;
            handshake.DeviceId = Input.GetJoystickNames()[LocalInputIndex];
            GamepadManager.InjectGamepadHandshake(handshake);
            IsRegistered = true;
        }
    }