Пример #1
0
 public static bool GetButtonUp(OuyaButton button, OuyaPlayer player)
 {
     /* this serves as the OUYA eguivalent to UNITY's Input.GetButtonUp()
      * returns true for the frame the button actually goes up
      */
     // return the button state for the frame it goes down (down event)
     return GetButton(button, ButtonAction.UpFrame, player);
 }
Пример #2
0
    private static bool GetButton(OuyaButton button, ButtonAction buttonAction, OuyaPlayer player)
    {
        /* for retreiving joystick button values from mapped Unity Input
         */

        /* NULL SECURITY */
        // check if there is no joystick connected
        if (controllerNames == null) return false;

        // check if there are more players than joysticks
        // this is not really needed in CLARK – just framework coherence
        int playerIndex = (int)player - 1;
        if (playerIndex >= controllerCount) return false;

        // finally check if we really found a joystick for the player
        OuyaMapType mapType = mapTypes[playerIndex];

        // get the controller mapping for the player
        PlayerController playerController = playerControllers[playerIndex];

        // this twisted recursive move is used for switch-mapped players
        OuyaPlayer mapPlayer = playerController.player;

        // secure that we have found a mapping
        if (playerController != null)
        {

            /* FIND THE CORRECT MAPPED BUTTON KEY */
            switch (mapType)
            {
                /* ANDROID MAPPINGS */
        #if !UNITY_EDITOR && UNITY_ANDROID
                case OuyaMapType.Broadcom_ANDROID:
                // tested mapping for: OuyaGameController connected to Nexus7
                // connected via standard Bluetooth connection
                case OuyaMapType.Generic_ANDROID:
                // tested mapping for: OuyaGameController connected to HTCOne
                // connected via standard Bluetooth connection
                switch (button)
                {
                    // ouya buttons
                    case OuyaButton.O:		return GetButton(0, buttonAction, mapPlayer);		// checked
                    case OuyaButton.U:		return GetButton(1, buttonAction, mapPlayer);		// checked
                    case OuyaButton.Y:		return GetButton(2, buttonAction, mapPlayer);		// checked
                    case OuyaButton.A:		return GetButton(3, buttonAction, mapPlayer);		// checked

                    // shoulder buttons
                    case OuyaButton.LB:		return GetButton(4, buttonAction, mapPlayer);		// checked
                    case OuyaButton.RB:		return GetButton(5, buttonAction, mapPlayer);		// checked

                    // stick buttons
                    case OuyaButton.L3:		return GetButton(6, buttonAction, mapPlayer);		// checked
                    case OuyaButton.R3:		return GetButton(7, buttonAction, mapPlayer);		// checked

                    // d-pad buttons
                    case OuyaButton.DU:		return GetButton(8, buttonAction, mapPlayer);		// checked
                    case OuyaButton.DD:		return GetButton(9, buttonAction, mapPlayer);		// checked
                    case OuyaButton.DL:		return GetButton(10, buttonAction, mapPlayer);		// checked
                    case OuyaButton.DR:		return GetButton(11, buttonAction, mapPlayer);		// checked

                    // trigger buttons
                    // although button states are natively supported we use axis conversion
                    // this is because trigger buttons will natively only react on full pullthrough
                    // these buttons then are two axis and do not give out UP or DOWN events natively
                    // we use button state management and continious scanning to provide these
                    case OuyaButton.LT: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                    case OuyaButton.RT: return GetCachedButtonEvent(button, buttonAction, playerIndex);

                    // not defined so far – or don't exist
                    case OuyaButton.START: 	return false;
                    case OuyaButton.SYSTEM: return false;
                    case OuyaButton.SELECT: return false;
                    default: return false;
                }

                case OuyaMapType.MogaPro_ANDROID:
                // this device was not tested yet
                // the setting were just extracted from some examples I found
                // please feedback if you find a way to test it
                switch (button)
                {
                    // OUYA buttons
                    case OuyaButton.O:		return GetButton(0, buttonAction, mapPlayer);
                    case OuyaButton.U:		return GetButton(3, buttonAction, mapPlayer);
                    case OuyaButton.Y:		return GetButton(4, buttonAction, mapPlayer);
                    case OuyaButton.A:		return GetButton(1, buttonAction, mapPlayer);

                    // shoulder buttons
                    case OuyaButton.LB:		return GetButton(6, buttonAction, mapPlayer);
                    case OuyaButton.RB:		return GetButton(7, buttonAction, mapPlayer);

                    // stick buttons
                    case OuyaButton.L3:		return GetButton(13, buttonAction, mapPlayer);
                    case OuyaButton.R3:		return GetButton(14, buttonAction, mapPlayer);

                    // d-pad buttons and trigger buttons
                    // these buttons are two axis and do not give out UP or DOWN events natively
                    // we use button state management and continious scanning to provide these
                    case OuyaButton.DU: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                    case OuyaButton.DD: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                    case OuyaButton.DL: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                    case OuyaButton.DR: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                    case OuyaButton.LT:	return GetCachedButtonEvent(button, buttonAction, playerIndex);
                    case OuyaButton.RT:	return GetCachedButtonEvent(button, buttonAction, playerIndex);

                    // not defined so far
                    case OuyaButton.START: 	return false;
                    case OuyaButton.SELECT: return false;
                    case OuyaButton.SYSTEM:	return false;
                    default: return false;
                }

                case OuyaMapType.GameStick_CONSOLE:
                // tested mapping for: GameStick console with native controller
                // connected via standard Bluetooth
                // triggers do not exist at all on this controller
                switch (button)
                {
                    // OUYA buttons
                    case OuyaButton.O: 		return GetButton(0, buttonAction, mapPlayer);		// checked
                    case OuyaButton.U: 		return GetButton(3, buttonAction, mapPlayer);		// checked
                    case OuyaButton.Y: 		return GetButton(4, buttonAction, mapPlayer);		// checked
                    case OuyaButton.A: 		return GetButton(1, buttonAction, mapPlayer);		// checked

                    // shoulder buttons
                    case OuyaButton.LB: 	return GetButton(6, buttonAction, mapPlayer);		// checked
                    case OuyaButton.RB: 	return GetButton(7, buttonAction, mapPlayer);		// checked

                    // stick buttons
                    case OuyaButton.L3: 	return GetButton(13, buttonAction, mapPlayer);		// checked
                    case OuyaButton.R3: 	return GetButton(14, buttonAction, mapPlayer);		// checked

                    // center buttons
                    case OuyaButton.SELECT: return GetButton(27, buttonAction, mapPlayer);		// checked
                    case OuyaButton.START: 	return GetButton(11, buttonAction, mapPlayer);		// checked

                    // d-pad buttons
                    // these buttons are two axis and do not give out UP or DOWN events natively
                    // we use button state management and continious scanning to provide these
                    case OuyaButton.DU: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                    case OuyaButton.DD: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                    case OuyaButton.DL: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                    case OuyaButton.DR: return GetCachedButtonEvent(button, buttonAction, playerIndex);

                    // the GameStick has no triggers
                    case OuyaButton.LT: return false;
                    case OuyaButton.RT: return false;

                    // SYSTEN is according to GameStick documents: joystick button 20
                    // but this is not valid in Unity (see script reference KeyCode)
                    case OuyaButton.SYSTEM: return false;
                    default: return false;
                }

                case OuyaMapType.Ouya_CONSOLE:
                // tested mapping for: OUYA console with native controller
                // connected via standard Bluetooth
                switch (button)
                {
                    // OUYA buttons
                    case OuyaButton.O:		return GetButton(0, buttonAction, mapPlayer);		// checked
                    case OuyaButton.U:		return GetButton(1, buttonAction, mapPlayer);		// checked
                    case OuyaButton.Y:		return GetButton(2, buttonAction, mapPlayer);		// checked
                    case OuyaButton.A:		return GetButton(3, buttonAction, mapPlayer);		// checked

                    // shoulder buttons
                    case OuyaButton.LB: 	return GetButton(4, buttonAction, mapPlayer);		// checked
                    case OuyaButton.RB: 	return GetButton(5, buttonAction, mapPlayer);		// checked

                    // stick buttons
                    case OuyaButton.L3:		return GetButton(6, buttonAction, mapPlayer);		// checked
                    case OuyaButton.R3:		return GetButton(7, buttonAction, mapPlayer);		// checked

                    // d-pad buttons
                    case OuyaButton.DU:		return GetButton(8, buttonAction, mapPlayer);		// checked
                    case OuyaButton.DD:		return GetButton(9, buttonAction, mapPlayer);		// checked
                    case OuyaButton.DL:		return GetButton(10, buttonAction, mapPlayer);		// checked
                    case OuyaButton.DR:		return GetButton(11, buttonAction, mapPlayer);		// checked

                    // trigger buttons
                    // although button states are natively supported we use axis conversion
                    // the button numbers we do not use are: LT 12 / RR 13
                    // this is because trigger buttons will natively only react on full pullthrough
                    // this feels very unresponsive and can be solved by evaluating the axis input values
                    // these two axis and do not give out UP or DOWN events natively
                    // we use button state management and continious scanning to provide these
                    case OuyaButton.LT: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                    case OuyaButton.RT: return GetCachedButtonEvent(button, buttonAction, playerIndex);

                    // not defined so far – or don't exist on OUYA
                    case OuyaButton.START: 	return false;
                    case OuyaButton.SYSTEM: return false;
                    case OuyaButton.SELECT: return false;
                    default: return false;
                }

                case OuyaMapType.XBOX360_ANDROID:
                // tested mapping for: XBOX360 USB controller connnected to OUYA, Nexus7
                // connected via USB cable (with USBToGo adapter cable for Nexus7)
                switch (button)
                {
                    // OUYA buttons
                    case OuyaButton.O: 		return GetButton(0, buttonAction, mapPlayer);		// checked
                    case OuyaButton.U: 		return GetButton(3, buttonAction, mapPlayer);		// checked
                    case OuyaButton.Y: 		return GetButton(4, buttonAction, mapPlayer);		// checked
                    case OuyaButton.A: 		return GetButton(1, buttonAction, mapPlayer);		// checked

                    // shoulder buttons
                    case OuyaButton.LB:		return GetButton(6, buttonAction, mapPlayer);		// checked
                    case OuyaButton.RB:		return GetButton(7, buttonAction, mapPlayer);		// checked

                    // center buttons
                    case OuyaButton.START: 	return GetButton(11, buttonAction, mapPlayer);		// checked
                    // this mapping for the select button works on OUYA but not on Nexus7
                    // Is it worth a complete new mapping section?
                    case OuyaButton.SELECT:	return GetButton(27, buttonAction, mapPlayer);

                    // stick buttons
                    case OuyaButton.L3: 	return GetButton(13, buttonAction, mapPlayer);		// checked
                    case OuyaButton.R3: 	return GetButton(14, buttonAction, mapPlayer);		// checked

                    // d-pad buttons and trigger buttons
                    // these buttons are two axis and do not give out UP or DOWN events natively
                    // we use button state management and continious scanning to provide these
                    case OuyaButton.DU: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                    case OuyaButton.DD: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                    case OuyaButton.DL: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                    case OuyaButton.DR: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                    case OuyaButton.LT:	return GetCachedButtonEvent(button, buttonAction, playerIndex);
                    case OuyaButton.RT:	return GetCachedButtonEvent(button, buttonAction, playerIndex);

                    // not defined so far
                    case OuyaButton.SYSTEM: return false;
                    default: return false;
                }

                case OuyaMapType.XBOX360_ANDROID_wireless:
                // tested mapping for: XBOX360 Wireless controller connected to OUYA
                // connected via MicrosoftWirelessReceiver which connects via USB cable
                switch (button)
                {
                    // OUYA buttons
                    case OuyaButton.O: 		return GetButton(0, buttonAction, mapPlayer);		// checked
                    case OuyaButton.U: 		return GetButton(3, buttonAction, mapPlayer);		// checked
                    case OuyaButton.Y: 		return GetButton(4, buttonAction, mapPlayer);		// checked
                    case OuyaButton.A: 		return GetButton(1, buttonAction, mapPlayer);		// checked

                    // shoulder buttons
                    case OuyaButton.LB:		return GetButton(6, buttonAction, mapPlayer);		// checked
                    case OuyaButton.RB:		return GetButton(7, buttonAction, mapPlayer);		// checked

                    // center buttons
                    case OuyaButton.START: 	return GetButton(11, buttonAction, mapPlayer);		// checked
                    case OuyaButton.SELECT:	return GetButton(27, buttonAction, mapPlayer);

                    // stick buttons
                    case OuyaButton.L3: 	return GetButton(13, buttonAction, mapPlayer);		// checked
                    case OuyaButton.R3: 	return GetButton(14, buttonAction, mapPlayer);		// checked

                    // d-pad buttons
                    // these buttons are very strange as they run on the same KeyCodes as O U (Y) A buttons
                    // so if we eant to work fine on Android we can't really use the d-pad
                    // that's why we partly deactivate these buttons via a flag
                    // pressing a d-pad button will still lead to [O U Y A] action button events
                    // this can't be helped – at leas we won't fire d-pad input when pressing action buttons
                    case OuyaButton.DU:
                    if (XBOX360W_ANDROID_DPAD) return GetButton(2, buttonAction, mapPlayer); else return false;
                    case OuyaButton.DD:
                    if (XBOX360W_ANDROID_DPAD) return GetButton(3, buttonAction, mapPlayer); else return false;
                    case OuyaButton.DL:
                    if (XBOX360W_ANDROID_DPAD) return GetButton(0, buttonAction, mapPlayer); else return false;
                    case OuyaButton.DR:
                    if (XBOX360W_ANDROID_DPAD) return GetButton(1, buttonAction, mapPlayer); else return false;

                    // trigger buttons
                    // these buttons are two axis and do not give out UP or DOWN events natively
                    // we use button state management and continious scanning to provide these
                    case OuyaButton.LT: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                    case OuyaButton.RT:	return GetCachedButtonEvent(button, buttonAction, playerIndex);

                    // not defined so far
                    case OuyaButton.SYSTEM: return false;
                    default: return false;
                }

                case OuyaMapType.PS3_ANDROID:
                // tested mapping for: PS3 DS controller connected to OUYA
                // connection via standard Bluetooth
                // pairing achieved using a temporary USB cable connection
                switch (button)
                {
                    // stick buttons
                    case OuyaButton.L3: 	return GetButton(1, buttonAction, mapPlayer);		// checked
                    case OuyaButton.R3: 	return GetButton(2, buttonAction, mapPlayer);		// checked

                    // center buttons
                    case OuyaButton.START: 	return GetButton(3, buttonAction, mapPlayer);		// checked
                    case OuyaButton.SELECT: return GetButton(27, buttonAction, mapPlayer);		// checked

                    // d-pad buttons
                    case OuyaButton.DU:		return GetButton(4, buttonAction, mapPlayer);		// checked
                    case OuyaButton.DR:		return GetButton(5, buttonAction, mapPlayer);		// checked
                    case OuyaButton.DD:		return GetButton(6, buttonAction, mapPlayer);		// checked
                    case OuyaButton.DL:		return GetButton(7, buttonAction, mapPlayer);		// checked

                    // trigger buttons
                    case OuyaButton.LT: 	return GetButton(8, buttonAction, mapPlayer);		// checked
                    case OuyaButton.RT: 	return GetButton(9, buttonAction, mapPlayer);		// checked

                    // shoulder buttons
                    case OuyaButton.LB:		return GetButton(10, buttonAction, mapPlayer);		// checked
                    case OuyaButton.RB:		return GetButton(11, buttonAction, mapPlayer);		// checked

                    // OUYA buttons
                    case OuyaButton.O:		return GetButton(14, buttonAction, mapPlayer);		// checked
                    case OuyaButton.U:		return GetButton(15, buttonAction, mapPlayer);		// checked
                    case OuyaButton.Y:		return GetButton(12, buttonAction, mapPlayer);		// checked
                    case OuyaButton.A:		return GetButton(13, buttonAction, mapPlayer);		// checked

                    // not defined do far
                    case OuyaButton.SYSTEM: return false;
                    default: return false;
                }
        #endif

                /* WINDOWS MAPPINGS */
        #if UNITY_EDITOR || UNITY_STANDALONE_WIN
                case OuyaMapType.Ouya_WIN:
                    // tested mapping for: OUYA Game Controller connected to Windows 7+8 64bit
                    // connection via standard Bluetooth (preinstalled OS drivers)
                    switch (button)
                    {
                        // shoulder buttons
                        case OuyaButton.LB: return GetButton(4, buttonAction, mapPlayer);		// checked
                        case OuyaButton.RB: return GetButton(5, buttonAction, mapPlayer);		// checked

                        // OUYA buttons
                        case OuyaButton.O: return GetButton(0, buttonAction, mapPlayer);		// checked
                        case OuyaButton.U: return GetButton(1, buttonAction, mapPlayer);		// checked
                        case OuyaButton.Y: return GetButton(2, buttonAction, mapPlayer);		// checked
                        case OuyaButton.A: return GetButton(3, buttonAction, mapPlayer);		// checked

                        // stick buttons
                        case OuyaButton.L3: return GetButton(6, buttonAction, mapPlayer);		// checked
                        case OuyaButton.R3: return GetButton(7, buttonAction, mapPlayer);		// checked

                        // d-pad buttons
                        case OuyaButton.DU: return GetButton(8, buttonAction, mapPlayer);		// checked
                        case OuyaButton.DD: return GetButton(9, buttonAction, mapPlayer);		// checked
                        case OuyaButton.DL: return GetButton(10, buttonAction, mapPlayer);		// checked
                        case OuyaButton.DR: return GetButton(11, buttonAction, mapPlayer);		// checked

                        // trigger buttons
                        // although button states are natively supported we use axis conversion
                        // the button numbers we do not use are: LT 12 / RR 13
                        // this is because trigger buttons will natively only react on full pullthrough
                        // this feels very unresponsive and can be solved by evaluating the axis input values
                        // these two axis and do not give out UP or DOWN events natively
                        // we use button state management and continious scanning to provide these
                        case OuyaButton.LT: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                        case OuyaButton.RT: return GetCachedButtonEvent(button, buttonAction, playerIndex);

                        // not defined so far – or don't exist on OUYA
                        case OuyaButton.START: return false;
                        case OuyaButton.SYSTEM: return false;
                        case OuyaButton.SELECT: return false;
                        default: return false;
                    }

                case OuyaMapType.XBox360_WIN:
                    switch (button)
                    // tested mapping for XBOX360 USB controller connected to Windows 7+8 64bit
                    // connection via USB cable (official Microsoft XBOX360 Drivers on Windows 7)
                    // connection via USB cable (preinstalled OS drivers on Windows 8)
                    {
                        // OUYA buttons
                        case OuyaButton.O: return GetButton(0, buttonAction, mapPlayer);		// checked
                        case OuyaButton.U: return GetButton(2, buttonAction, mapPlayer);		// checked
                        case OuyaButton.Y: return GetButton(3, buttonAction, mapPlayer);		// checked
                        case OuyaButton.A: return GetButton(1, buttonAction, mapPlayer);		// checked

                        // shoulder buttons
                        case OuyaButton.LB: return GetButton(4, buttonAction, mapPlayer);		// checked
                        case OuyaButton.RB: return GetButton(5, buttonAction, mapPlayer);		// checked

                        // center buttons
                        case OuyaButton.START: return GetButton(7, buttonAction, mapPlayer);		// checked
                        case OuyaButton.SELECT: return GetButton(6, buttonAction, mapPlayer);		// checked

                        // stick buttons
                        case OuyaButton.L3: return GetButton(8, buttonAction, mapPlayer);		// checked
                        case OuyaButton.R3: return GetButton(9, buttonAction, mapPlayer);		// checked

                        // d-pad buttons and trigger buttons
                        // these buttons are two axis and do not give out UP or DOWN events natively
                        // we use button state management and continious scanning to provide these
                        case OuyaButton.DU: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                        case OuyaButton.DD: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                        case OuyaButton.DL: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                        case OuyaButton.DR: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                        case OuyaButton.LT: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                        case OuyaButton.RT: return GetCachedButtonEvent(button, buttonAction, playerIndex);

                        //  not defined so far
                        case OuyaButton.SYSTEM: return false;
                        default: return false;
                    }

                case OuyaMapType.PS3_WIN:
                    // tested mapping for: PS3 DS controller connected to Windows 8 64bit
                    // connection via standard Bluetooth (preinstalled OS drivers)
                    // pairing achieved using a temporary USB cable connection
                    switch (button)
                    {
                        // stick buttons
                        case OuyaButton.L3: return GetButton(1, buttonAction, mapPlayer);		// checked
                        case OuyaButton.R3: return GetButton(2, buttonAction, mapPlayer);		// checked

                        // center buttons
                        case OuyaButton.START: return GetButton(3, buttonAction, mapPlayer);		// checked
                        case OuyaButton.SELECT: return GetButton(0, buttonAction, mapPlayer);		// checked

                        // d-pad buttons
                        case OuyaButton.DU: return GetButton(4, buttonAction, mapPlayer);		// checked
                        case OuyaButton.DR: return GetButton(5, buttonAction, mapPlayer);		// checked
                        case OuyaButton.DD: return GetButton(6, buttonAction, mapPlayer);		// checked
                        case OuyaButton.DL: return GetButton(7, buttonAction, mapPlayer);		// checked

                        // trigger buttons
                        case OuyaButton.LT: return GetButton(8, buttonAction, mapPlayer);		// checked
                        case OuyaButton.RT: return GetButton(9, buttonAction, mapPlayer);		// checked

                        // shoulder buttons
                        case OuyaButton.LB: return GetButton(10, buttonAction, mapPlayer);		// checked
                        case OuyaButton.RB: return GetButton(11, buttonAction, mapPlayer);		// checked

                        // OUYA buttons
                        case OuyaButton.O: return GetButton(14, buttonAction, mapPlayer);		// checked
                        case OuyaButton.U: return GetButton(15, buttonAction, mapPlayer);		// checked
                        case OuyaButton.Y: return GetButton(12, buttonAction, mapPlayer);		// checked
                        case OuyaButton.A: return GetButton(13, buttonAction, mapPlayer);		// checked

                        // not defined do far
                        case OuyaButton.SYSTEM: return false;
                        default: return false;
                    }

                case OuyaMapType.MotionInJoy_WIN:
                    // tested mapping for: PS3 DS controller connected to Windows 7 64bit
                    // connection via USB cable (custom setup using the most popular but crappy driver: MotionInJoy)
                    // this needs a CUSTOM button mapping setup in the driver tools to work (see documentation)
                    // default sets could not be used as they do not make sense (gyro's and sticks share the same axis)
                    // READ THE DOCUMENTATION to make this work !!!
                    switch (button)
                    {
                        // OUYA buttons
                        case OuyaButton.O: return GetButton(2, buttonAction, mapPlayer);		// checked
                        case OuyaButton.U: return GetButton(3, buttonAction, mapPlayer);		// checked
                        case OuyaButton.Y: return GetButton(0, buttonAction, mapPlayer);		// checked
                        case OuyaButton.A: return GetButton(1, buttonAction, mapPlayer);		// checked

                        // shoulder buttons
                        case OuyaButton.LB: return GetButton(4, buttonAction, mapPlayer);		// checked
                        case OuyaButton.RB: return GetButton(5, buttonAction, mapPlayer);		// checked

                        // trigger buttons
                        case OuyaButton.LT: return GetButton(6, buttonAction, mapPlayer);		// checked
                        case OuyaButton.RT: return GetButton(7, buttonAction, mapPlayer);		// checked

                        // stick buttons
                        case OuyaButton.L3: return GetButton(8, buttonAction, mapPlayer);		// checked
                        case OuyaButton.R3: return GetButton(9, buttonAction, mapPlayer);		// checked

                        // center buttons
                        case OuyaButton.SELECT: return GetButton(10, buttonAction, mapPlayer);		// checked
                        case OuyaButton.START: return GetButton(11, buttonAction, mapPlayer);		// checked
                        case OuyaButton.SYSTEM: return GetButton(12, buttonAction, mapPlayer);		// checked

                        // d-pad buttons
                        case OuyaButton.DU: return GetButton(13, buttonAction, mapPlayer);		// checked
                        case OuyaButton.DR: return GetButton(14, buttonAction, mapPlayer);		// checked
                        case OuyaButton.DD: return GetButton(15, buttonAction, mapPlayer);		// checked
                        case OuyaButton.DL: return GetButton(16, buttonAction, mapPlayer);		// checked

                        // not defined do far
                        default: return false;
                    }

                case OuyaMapType.GameStick_WIN:
                    // the GameStick has no working driver on Windows
                    // so far we can't support the device although we know it's name at least
                    // this is just a placeholder where real mapping should be once we find a driver
                    switch (button)
                    {
                        // OUYA buttons
                        case OuyaButton.O: return GetButton(0, buttonAction, mapPlayer);
                        case OuyaButton.U: return GetButton(3, buttonAction, mapPlayer);
                        case OuyaButton.Y: return GetButton(4, buttonAction, mapPlayer);
                        case OuyaButton.A: return GetButton(1, buttonAction, mapPlayer);

                        // shoulder buttons
                        case OuyaButton.LB: return GetButton(6, buttonAction, mapPlayer);
                        case OuyaButton.RB: return GetButton(7, buttonAction, mapPlayer);

                        // stick buttons
                        case OuyaButton.L3: return GetButton(13, buttonAction, mapPlayer);
                        case OuyaButton.R3: return GetButton(14, buttonAction, mapPlayer);

                        // center buttons
                        case OuyaButton.SELECT: return GetButton(27, buttonAction, mapPlayer);
                        case OuyaButton.START: return GetButton(11, buttonAction, mapPlayer);

                        // d-pad buttons
                        // these buttons are two axis and do not give out UP or DOWN events natively
                        // we use button state management and continious scanning to provide these
                        case OuyaButton.DU: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                        case OuyaButton.DD: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                        case OuyaButton.DL: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                        case OuyaButton.DR: return GetCachedButtonEvent(button, buttonAction, playerIndex);

                        // the GameStick has no triggers
                        case OuyaButton.LT: return false;
                        case OuyaButton.RT: return false;

                        // SYSTEN is according to GameStick documents: joystick button 20
                        // but this is not valid in Unity (see script reference Keycode)
                        case OuyaButton.SYSTEM: return false;
                        default: return false;
                    }
        #endif

                /* MACOSX MAPPINGS */
        #if UNITY_EDITOR || UNITY_STANDALONE_OSX
                case OuyaMapType.PS3_OSX:
                    // tested mapping for PS3 DS controller connected to the MacOSX
                    // connection via standard Bluetooth (prinstalled drivers)
                    // pairing achieved using a temporary USB cable connection
                    switch (button)
                    {
                        // stick buttons
                        case OuyaButton.L3: return GetButton(1, buttonAction, mapPlayer);		// checked
                        case OuyaButton.R3: return GetButton(2, buttonAction, mapPlayer);		// checked

                        // center buttons
                        case OuyaButton.START: return GetButton(3, buttonAction, mapPlayer);		// checked
                        case OuyaButton.SELECT: return GetButton(0, buttonAction, mapPlayer);		// checked

                        // d-pad buttons
                        case OuyaButton.DU: return GetButton(4, buttonAction, mapPlayer);		// checked
                        case OuyaButton.DR: return GetButton(5, buttonAction, mapPlayer);		// checked
                        case OuyaButton.DD: return GetButton(6, buttonAction, mapPlayer);		// checked
                        case OuyaButton.DL: return GetButton(7, buttonAction, mapPlayer);		// checked

                        // trigger buttons
                        case OuyaButton.LT: return GetButton(8, buttonAction, mapPlayer);		// checked
                        case OuyaButton.RT: return GetButton(9, buttonAction, mapPlayer);		// checked

                        // shoulder buttons
                        case OuyaButton.LB: return GetButton(10, buttonAction, mapPlayer);		// checked
                        case OuyaButton.RB: return GetButton(11, buttonAction, mapPlayer);		// checked

                        // OUYA buttons
                        case OuyaButton.O: return GetButton(14, buttonAction, mapPlayer);		// checked
                        case OuyaButton.U: return GetButton(15, buttonAction, mapPlayer);		// checked
                        case OuyaButton.Y: return GetButton(12, buttonAction, mapPlayer);		// checked
                        case OuyaButton.A: return GetButton(13, buttonAction, mapPlayer);		// checked

                        // not defined do far
                        case OuyaButton.SYSTEM: return false;
                        default: return false;
                    }

                case OuyaMapType.TattieBogle_OSX:
                    // tested mapping for: XBOX360 USB controller connected to MacOSX
                    // tested mapping for: XBOX360 Wireless controller connected to MacOSX
                    // connection via USB cable (with the free to dowload TattieBogle driver)
                    // NOTE: disconnecting a XBOX360 USB controller using Tattie can lead to full system reboot
                    switch (button)
                    {
                        // shoulder buttons
                        case OuyaButton.LB: return GetButton(13, buttonAction, mapPlayer);		// checked
                        case OuyaButton.RB: return GetButton(14, buttonAction, mapPlayer);		// checked

                        // OUYA buttons
                        case OuyaButton.O: return GetButton(16, buttonAction, mapPlayer);		// checked
                        case OuyaButton.U: return GetButton(18, buttonAction, mapPlayer);		// checked
                        case OuyaButton.Y: return GetButton(19, buttonAction, mapPlayer);		// checked
                        case OuyaButton.A: return GetButton(17, buttonAction, mapPlayer);		// checked

                        // stick buttons
                        case OuyaButton.L3: return GetButton(11, buttonAction, mapPlayer);		// checked
                        case OuyaButton.R3: return GetButton(12, buttonAction, mapPlayer);		// checked

                        // center buttons
                        case OuyaButton.SELECT: return GetButton(10, buttonAction, mapPlayer);		// checked
                        case OuyaButton.START: return GetButton(9, buttonAction, mapPlayer);		// checked
                        case OuyaButton.SYSTEM: return GetButton(15, buttonAction, mapPlayer);		// checked

                        // d-pad buttons
                        case OuyaButton.DU: return GetButton(5, buttonAction, mapPlayer);		// checked
                        case OuyaButton.DD: return GetButton(6, buttonAction, mapPlayer);		// checked
                        case OuyaButton.DL: return GetButton(7, buttonAction, mapPlayer);		// checked
                        case OuyaButton.DR: return GetButton(8, buttonAction, mapPlayer);		// checked

                        // trigger buttons
                        // the triggers are axis and do not give out UP or DOWN events natively
                        // we use button state management and continious scanning to provide these
                        case OuyaButton.LT: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                        case OuyaButton.RT: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                        default: return false;
                    }

                case OuyaMapType.GameStick_OSX:
                    // the GameStick has no working driver on MacOSX
                    // so far we can't support the device although we know it's name at least
                    // this is just a placeholder where real mapping should be once we find a driver
                    switch (button)
                    {
                        // OUYA buttons
                        case OuyaButton.O: return GetButton(0, buttonAction, mapPlayer);
                        case OuyaButton.U: return GetButton(3, buttonAction, mapPlayer);
                        case OuyaButton.Y: return GetButton(4, buttonAction, mapPlayer);
                        case OuyaButton.A: return GetButton(1, buttonAction, mapPlayer);

                        // shoulder buttons
                        case OuyaButton.LB: return GetButton(6, buttonAction, mapPlayer);
                        case OuyaButton.RB: return GetButton(7, buttonAction, mapPlayer);

                        // stick buttons
                        case OuyaButton.L3: return GetButton(13, buttonAction, mapPlayer);
                        case OuyaButton.R3: return GetButton(14, buttonAction, mapPlayer);

                        // center buttons
                        case OuyaButton.SELECT: return GetButton(27, buttonAction, mapPlayer);
                        case OuyaButton.START: return GetButton(11, buttonAction, mapPlayer);

                        // d-pad buttons
                        // these buttons are two axis and do not give out UP or DOWN events natively
                        // we use button state management and continious scanning to provide these
                        case OuyaButton.DU: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                        case OuyaButton.DD: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                        case OuyaButton.DL: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                        case OuyaButton.DR: return GetCachedButtonEvent(button, buttonAction, playerIndex);

                        // the GameStick has no triggers
                        case OuyaButton.LT: return false;
                        case OuyaButton.RT: return false;

                        // SYSTEN is according to GameStick documents: joystick button 20
                        // but this is not valid in Unity (see script reference Keycode)
                        case OuyaButton.SYSTEM: return false;
                        default: return false;
                    }
        #endif

                /* UNKNOWN MAPPINGS */
                case OuyaMapType.Unknown:
                    // we hope to catch any unkown bluetooth controllers here (wild card)
                    // there can't be any testing for that as it's just a random try
                    switch (button)
                    {
                        // ouya buttons
                        case OuyaButton.O: return GetButton(0, buttonAction, mapPlayer);
                        case OuyaButton.U: return GetButton(3, buttonAction, mapPlayer);
                        case OuyaButton.Y: return GetButton(4, buttonAction, mapPlayer);
                        case OuyaButton.A: return GetButton(1, buttonAction, mapPlayer);

                        // shoulder buttons
                        case OuyaButton.LB: return GetButton(6, buttonAction, mapPlayer);
                        case OuyaButton.RB: return GetButton(7, buttonAction, mapPlayer);

                        // stick buttons
                        case OuyaButton.L3: return GetButton(13, buttonAction, mapPlayer);
                        case OuyaButton.R3: return GetButton(14, buttonAction, mapPlayer);

                        // d-pad buttons and trigger buttons
                        // tese buttons are axis and do not give out UP or DOWN events natively
                        // we use button state management and continious scanning to provide these
                        case OuyaButton.DU: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                        case OuyaButton.DD: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                        case OuyaButton.DL: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                        case OuyaButton.DR: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                        case OuyaButton.LT: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                        case OuyaButton.RT: return GetCachedButtonEvent(button, buttonAction, playerIndex);

                        // not defined so far
                        default: return false;
                    }
            }
        }
        /* SECURITY FALL THROUGH RETURN */
        return false;
    }
Пример #3
0
 public static bool GetButton(OuyaButton button, OuyaPlayer player)
 {
     /* this serves as the OUYA eguivalent to UNITY's Input.GetButton()
      * returns true if the button is pressed
      */
     // return the button state for pressed (down state)
     return GetButton(button, ButtonAction.Pressed, player);
 }
Пример #4
0
    private static bool GetCachedButtonEvent(OuyaButton button, ButtonAction buttonAction, int playerIndex)
    {
        /* this allows to retreive button events discovered by continious scanning
         * this will sreturn false for ButtonUp and ButtonDown if continioussScanning is not activated
         */
        // get the correct player from the index
        OuyaPlayer player = (OuyaPlayer)(playerIndex + 1);

        switch (button)
        {
            // d-pad buttons
            // some d-pad buttons are two axis and do not give out UP or DOWN events natively
            // we use button state management and continious scanning to provide these
            case OuyaButton.DU:
                switch (buttonAction)
                {
                    case ButtonAction.DownFrame: return playerControllers[playerIndex].downEventDU;
                    case ButtonAction.UpFrame: return playerControllers[playerIndex].upEventDU;
                    default: return GetAxis(OuyaAxis.DY, player) > 0f;
                }
            case OuyaButton.DD:
                switch (buttonAction)
                {
                    case ButtonAction.DownFrame: return playerControllers[playerIndex].downEventDD;
                    case ButtonAction.UpFrame: return playerControllers[playerIndex].upEventDD;
                    default: return GetAxis(OuyaAxis.DY, player) < 0f;
                }
            case OuyaButton.DL:
                switch (buttonAction)
                {
                    case ButtonAction.DownFrame: return playerControllers[playerIndex].downEventDL;
                    case ButtonAction.UpFrame: return playerControllers[playerIndex].upEventDL;
                    default: return GetAxis(OuyaAxis.DX, player) < 0f;
                }
            case OuyaButton.DR:
                switch (buttonAction)
                {
                    case ButtonAction.DownFrame: return playerControllers[playerIndex].downEventDR;
                    case ButtonAction.UpFrame: return playerControllers[playerIndex].upEventDR;
                    default: return GetAxis(OuyaAxis.DX, player) > 0f;
                }
            // trigger buttons
            // some triggers are axis and do not give out UP or DOWN events natively
            // we use button state management and continious scanning to provide these
            case OuyaButton.LT:
                switch (buttonAction)
                {
                    case ButtonAction.DownFrame: return playerControllers[playerIndex].downEventLT;
                    case ButtonAction.UpFrame: return playerControllers[playerIndex].upEventLT;
                    default: return GetAxis(OuyaAxis.LT, player) > triggerThreshold;
                }
            case OuyaButton.RT:
                switch (buttonAction)
                {
                    case ButtonAction.DownFrame: return playerControllers[playerIndex].downEventRT;
                    case ButtonAction.UpFrame: return playerControllers[playerIndex].upEventRT;
                    default: return GetAxis(OuyaAxis.RT, player) > triggerThreshold;
                }
            // not defined so far
            default: return false;
        }
    }
Пример #5
0
    private static bool GetButton(OuyaButton button, ButtonAction buttonAction, OuyaPlayer player)
    {
        /* for retreiving joystick button values from mapped Unity Input
         */

        /* NULL SECURITY */
        // check if there is no joystick connected
        if (controllerNames == null) return false;

        // check if there are more players than joysticks
        // this is not really needed in CLARK – just framework coherence
        int playerIndex = (int) player - 1;
        if (playerIndex >= controllerCount) return false;

        // finally check if we really found a joystick for the player
        OuyaControllerType controllerType = controllerTypes[playerIndex];

        // get the controller mapping for the player
        PlayerController playerController = playerControllers[playerIndex];

        // secure that we have found a mapping
        if (playerController != null) {

        /* FIND THE CORRECT MAPPED BUTTON KEY */
            switch (controllerType) {
        #if !UNITY_EDITOR && UNITY_ANDROID
            case OuyaControllerType.Broadcom:
            case OuyaControllerType.MogaPro:
                // this device was not tested yet
                // the setting were just extracted from some examples I found
                // please feedback if you find a way to test it
                switch (button)
                {
                // shoulder buttons
                case OuyaButton.LB:		return GetButton(6, buttonAction, player);
                case OuyaButton.RB:		return GetButton(7, buttonAction, player);

                // OUYA buttons
                case OuyaButton.O:		return GetButton(0, buttonAction, player);
                case OuyaButton.U:		return GetButton(3, buttonAction, player);
                case OuyaButton.Y:		return GetButton(4, buttonAction, player);
                case OuyaButton.A:		return GetButton(1, buttonAction, player);

                // stick buttons
                case OuyaButton.L3:		return GetButton(13, buttonAction, player);
                case OuyaButton.R3:		return GetButton(14, buttonAction, player);

                // d-pad buttons and trigger buttons
                // these buttons are two axis and do not give out UP or DOWN events natively
                // we use button state management and continious scanning to provide these
                case OuyaButton.DU: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                case OuyaButton.DD: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                case OuyaButton.DL: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                case OuyaButton.DR: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                case OuyaButton.LT:	return GetCachedButtonEvent(button, buttonAction, playerIndex);
                case OuyaButton.RT:	return GetCachedButtonEvent(button, buttonAction, playerIndex);

                // not defined so far
                case OuyaButton.START: 	return false;
                case OuyaButton.SELECT: return false;
                case OuyaButton.SYSTEM:	return false;
                default: return false;
                }

            case OuyaControllerType.GameStick:
                // tested on the real GameStick DevKit
                // never succeded in pairing the controller with the Ouya, Mac, Windows
                // strangely enough the flat d-pad has pressure sensitive axis output
                // triggers do not exist at all on this controller
                switch (button)
                {
                // OUYA buttons
                case OuyaButton.O: 		return GetButton(0, buttonAction, player);		// checked
                case OuyaButton.U: 		return GetButton(3, buttonAction, player);		// checked
                case OuyaButton.Y: 		return GetButton(4, buttonAction, player);		// checked
                case OuyaButton.A: 		return GetButton(1, buttonAction, player);		// checked

                // shoulder buttons
                case OuyaButton.LB: 	return GetButton(6, buttonAction, player);		// checked
                case OuyaButton.RB: 	return GetButton(7, buttonAction, player);		// checked

                // stick buttons
                case OuyaButton.L3: 	return GetButton(13, buttonAction, player);		// checked
                case OuyaButton.R3: 	return GetButton(14, buttonAction, player);		// checked

                // center buttons
                case OuyaButton.SELECT: return GetButton(27, buttonAction, player);		// checked
                case OuyaButton.START: 	return GetButton(11, buttonAction, player);		// checked

                // d-pad buttons
                // these buttons are two axis and do not give out UP or DOWN events natively
                // we use button state management and continious scanning to provide these
                case OuyaButton.DU: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                case OuyaButton.DD: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                case OuyaButton.DL: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                case OuyaButton.DR: return GetCachedButtonEvent(button, buttonAction, playerIndex);

                // the GameStick has no triggers
                case OuyaButton.LT: return false;
                case OuyaButton.RT: return false;

                // SYSTEN is according to GameStick documents: joystick button 20
                // but this is not valid in Unity (see script reference Keycode)
                case OuyaButton.SYSTEM: return false;
                default: return false;
                }
        #endif
            case OuyaControllerType.Ouya:
        #if !UNITY_EDITOR && UNITY_ANDROID
                // tested on the real Ouya Developers Console
                // the d-pad has no pressure sensitive output although the hardware looks like it
                // triggers have both: pressure sensitive axis and button event output (nice)
                switch (button)
                {
                // shoulder buttons
                case OuyaButton.LB: 	return GetButton(4, buttonAction, player);		// checked
                case OuyaButton.RB: 	return GetButton(5, buttonAction, player);		// checked

                // OUYA buttons
                case OuyaButton.O:		return GetButton(0, buttonAction, player);		// checked
                case OuyaButton.U:		return GetButton(1, buttonAction, player);		// checked
                case OuyaButton.Y:		return GetButton(2, buttonAction, player);		// checked
                case OuyaButton.A:		return GetButton(3, buttonAction, player);		// checked

                // stick buttons
                case OuyaButton.L3:		return GetButton(6, buttonAction, player);		// checked
                case OuyaButton.R3:		return GetButton(7, buttonAction, player);		// checked

                // d-pad buttons
                case OuyaButton.DU:		return GetButton(8, buttonAction, player);		// checked
                case OuyaButton.DD:		return GetButton(9, buttonAction, player);		// checked
                case OuyaButton.DL:		return GetButton(10, buttonAction, player);		// checked
                case OuyaButton.DR:		return GetButton(11, buttonAction, player);		// checked

                // trigger buttons
                case OuyaButton.LT:		return GetButton(12, buttonAction, player);		// checked
                case OuyaButton.RT:		return GetButton(13, buttonAction, player);		// checked

                // not defined so far – or don't exist on OUYA
                case OuyaButton.START: return false;
                case OuyaButton.SYSTEM: return false;
                case OuyaButton.SELECT: return false;
                default: return false;
                }
        #else
                // tested on Windows8 64bit (standalone player) – pairing via OS Bluetooth driver
                // the d-pad has no pressure sensitive output although the hardware looks like it
                // triggers have both: pressure sensitive axis and button event output
                // however trigger buttons only react on full pullthrough
                // therefore we prefer to use axis conversion
                switch (button)
                {
                // shoulder buttons
                case OuyaButton.LB: 	return GetButton(4, buttonAction, player);		// checked
                case OuyaButton.RB: 	return GetButton(5, buttonAction, player);		// checked

                // OUYA buttons
                case OuyaButton.O:		return GetButton(0, buttonAction, player);		// checked
                case OuyaButton.U:		return GetButton(1, buttonAction, player);		// checked
                case OuyaButton.Y:		return GetButton(2, buttonAction, player);		// checked
                case OuyaButton.A:		return GetButton(3, buttonAction, player);		// checked

                // stick buttons
                case OuyaButton.L3:		return GetButton(6, buttonAction, player);		// checked
                case OuyaButton.R3:		return GetButton(7, buttonAction, player);		// checked

                // d-pad buttons
                case OuyaButton.DU:		return GetButton(8, buttonAction, player);		// checked
                case OuyaButton.DD:		return GetButton(9, buttonAction, player);		// checked
                case OuyaButton.DL:		return GetButton(10, buttonAction, player);		// checked
                case OuyaButton.DR:		return GetButton(11, buttonAction, player);		// checked

                // trigger buttons
                // although button states are natively supported we use axis conversion
                // this is because trigger buttons will natively only react on full pullthrough
                // these buttons then are two axis and do not give out UP or DOWN events natively
                // we use button state management and continious scanning to provide these
                case OuyaButton.LT: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                case OuyaButton.RT: return GetCachedButtonEvent(button, buttonAction, playerIndex);

                // not defined so far – or don't exist on OUYA
                case OuyaButton.START: return false;
                case OuyaButton.SYSTEM: return false;
                case OuyaButton.SELECT: return false;
                default: return false;
                }
        #endif
            case OuyaControllerType.XBox360:
        #if !UNITY_EDITOR && UNITY_ANDROID
                // tested with the XBOX360 standard controller connected to the OUYA via USB
                // hopefully wireless XBOX controllers connected via Bluetooth have the same values
                // the d-pad has sensitive pressure axis output – however we won't get button events
                // we need to use continious input scanning for managing Buttonup or ButtonDown events
                // the same is true for the pressure sensitive axis triggers
                switch (button)
                {
                // OUYA buttons
                case OuyaButton.O: 		return GetButton(0, buttonAction, player);		// checked
                case OuyaButton.U: 		return GetButton(3, buttonAction, player);		// checked
                case OuyaButton.Y: 		return GetButton(4, buttonAction, player);		// checked
           		case OuyaButton.A: 		return GetButton(1, buttonAction, player);		// checked

                // shoulder buttons
                case OuyaButton.LB:		return GetButton(6, buttonAction, player);		// checked
                case OuyaButton.RB:		return GetButton(7, buttonAction, player);		// checked

                // center buttons
                case OuyaButton.START: 	return GetButton(11, buttonAction, player);		// checked
                case OuyaButton.SELECT:	return GetButton(27, buttonAction, player);

                // stick buttons
                case OuyaButton.L3: 	return GetButton(13, buttonAction, player);		// checked
                case OuyaButton.R3: 	return GetButton(14, buttonAction, player);		// checked

                // d-pad buttons and trigger buttons
                // these buttons are two axis and do not give out UP or DOWN events natively
                // we use button state management and continious scanning to provide these
                case OuyaButton.DU: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                case OuyaButton.DD: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                case OuyaButton.DL: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                case OuyaButton.DR: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                case OuyaButton.LT:	return GetCachedButtonEvent(button, buttonAction, playerIndex);
                case OuyaButton.RT:	return GetCachedButtonEvent(button, buttonAction, playerIndex);

                // not defined so far
                case OuyaButton.SYSTEM: return false;
                default: return false;
                }
        #else
                switch (button)
                // tested with the XBOX360 standard controller connected to a Win64 machine via USB and official driver
                // hopefully wireless XBOX controllers connected via Bluetooth have the same values
                // the d-pad has sensitive pressure axis output – however we won't get button events
                // we need to use continious input scanning for managing Buttonup or ButtonDown events
                // the same is true for the pressure sensitive axis triggers
                // this block won't treat the XBOX360 controller running on MacOSX
                // on MacOSX we use the TattieBogle driver which leads to a different controller type
                {
                // OUYA buttons
                case OuyaButton.O:		return GetButton(0, buttonAction, player);		// checked
                case OuyaButton.U:		return GetButton(2, buttonAction, player);		// checked
                case OuyaButton.Y:		return GetButton(3, buttonAction, player);		// checked
                case OuyaButton.A:		return GetButton(1, buttonAction, player);		// checked

                // shoulder buttons
                case OuyaButton.LB:		return GetButton(4, buttonAction, player);		// checked
                case OuyaButton.RB:		return GetButton(5, buttonAction, player);		// checked

                // center buttons
                case OuyaButton.START:	return GetButton(7, buttonAction, player);		// checked
                case OuyaButton.SELECT: return GetButton(6, buttonAction, player);		// checked

                // stick buttons
                case OuyaButton.L3: 	return GetButton(8, buttonAction, player);		// checked
                case OuyaButton.R3: 	return GetButton(9, buttonAction, player);		// checked

                // d-pad buttons and trigger buttons
                // these buttons are two axis and do not give out UP or DOWN events natively
                // we use button state management and continious scanning to provide these
                case OuyaButton.DU: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                case OuyaButton.DD: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                case OuyaButton.DL: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                case OuyaButton.DR: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                case OuyaButton.LT:	return GetCachedButtonEvent(button, buttonAction, playerIndex);
                case OuyaButton.RT:	return GetCachedButtonEvent(button, buttonAction, playerIndex);

                //  not defined so far
                case OuyaButton.SYSTEM: return false;
                default: return false;
                }
        #endif
            case OuyaControllerType.PS3:
        #if !UNITY_EDITOR && UNITY_ANDROID
                // tested with the PS3 standard controller connected to the OUYA via Bluetooth
                // pairing was achieved using a temporary USB cable connection to the OUYA
                // the d-pad uses simple button events – there is no pressure sensitivity here
                // triggers have both: pressure sentive axis output as well as button events
                switch (button)
                {
               	// stick buttons
                case OuyaButton.L3: 	return GetButton(1, buttonAction, player);		// checked
                case OuyaButton.R3: 	return GetButton(2, buttonAction, player);		// checked

                // center buttons
                case OuyaButton.START: 	return GetButton(3, buttonAction, player);		// checked
                case OuyaButton.SELECT: return GetButton(27, buttonAction, player);		// checked

                // d-pad buttons
                case OuyaButton.DU:		return GetButton(4, buttonAction, player);		// checked
                case OuyaButton.DR:		return GetButton(5, buttonAction, player);		// checked
                case OuyaButton.DD:		return GetButton(6, buttonAction, player);		// checked
                case OuyaButton.DL:		return GetButton(7, buttonAction, player);		// checked

                // trigger buttons
                case OuyaButton.LT: 	return GetButton(8, buttonAction, player);		// checked
                case OuyaButton.RT: 	return GetButton(9, buttonAction, player);		// checked

                // shoulder buttons
                case OuyaButton.LB:		return GetButton(10, buttonAction, player);		// checked
                case OuyaButton.RB:		return GetButton(11, buttonAction, player);		// checked

                // OUYA buttons
                case OuyaButton.O:		return GetButton(14, buttonAction, player);		// checked
                case OuyaButton.U:		return GetButton(15, buttonAction, player);		// checked
                case OuyaButton.Y:		return GetButton(12, buttonAction, player);		// checked
                case OuyaButton.A:		return GetButton(13, buttonAction, player);		// checked

                // not defined do far
                case OuyaButton.SYSTEM: return false;
                default: return false;
                }
        #elif !UNITY_EDITOR && UNITY_STANDALONE_OSX
                // tested with the PS3 standard controller connected to the MacOSX via Bluetooth
                // pairing was achieved using a temporary USB cable connection to the Mac
                // the d-pad and triggers use simple button events – there is no pressure sensitivity here
                // this is because the standard Mac connection doesn't show all the features of the controller
                // we would need a designated 3rd party driver for that
                switch (button)
                {
               	// stick buttons
                case OuyaButton.L3: 	return GetButton(1, buttonAction, player);		// checked
                case OuyaButton.R3: 	return GetButton(2, buttonAction, player);		// checked

                // center buttons
                case OuyaButton.START: 	return GetButton(3, buttonAction, player);		// checked
                case OuyaButton.SELECT: return GetButton(0, buttonAction, player);		// checked

                // d-pad buttons
                case OuyaButton.DU:		return GetButton(4, buttonAction, player);		// checked
                case OuyaButton.DR:		return GetButton(5, buttonAction, player);		// checked
                case OuyaButton.DD:		return GetButton(6, buttonAction, player);		// checked
                case OuyaButton.DL:		return GetButton(7, buttonAction, player);		// checked

                // trigger buttons
                case OuyaButton.LT: 	return GetButton(8, buttonAction, player);		// checked
                case OuyaButton.RT: 	return GetButton(9, buttonAction, player);		// checked

                // shoulder buttons
                case OuyaButton.LB:		return GetButton(10, buttonAction, player);		// checked
                case OuyaButton.RB:		return GetButton(11, buttonAction, player);		// checked

                // OUYA buttons
                case OuyaButton.O:		return GetButton(14, buttonAction, player);		// checked
                case OuyaButton.U:		return GetButton(15, buttonAction, player);		// checked
                case OuyaButton.Y:		return GetButton(12, buttonAction, player);		// checked
                case OuyaButton.A:		return GetButton(13, buttonAction, player);		// checked

                // not defined do far
                case OuyaButton.SYSTEM: return false;
                default: return false;
                }
        #elif !UNITY_EDITOR && UNITY_STANDALONE_WIN
                // tested with the PS3 standard controller connected to Win7 64 via USB
                // custom setup was done using the most popular but crappy driver: MotionInJoy
                // this needs a CUSTOM button mapping setup in the driver tools to work (see documentation)
                // default sets could not be used as they do not make sense (gyro's and sticks share the same axis)
                // the d-pad use simple button events – there is no pressure sensitivity here
                // the triggers provide both: pressure sensitive axis output and button events
                // READ THE DOCUMENTATION to make this work !!!
                switch (button)
                {
                // OUYA buttons
                case OuyaButton.O:		return GetButton(2, buttonAction, player);		// checked
                case OuyaButton.U:		return GetButton(3, buttonAction, player);		// checked
                case OuyaButton.Y:		return GetButton(0, buttonAction, player);		// checked
                case OuyaButton.A:		return GetButton(1, buttonAction, player);		// checked

                // shoulder buttons
                case OuyaButton.LB:		return GetButton(4, buttonAction, player);		// checked
                case OuyaButton.RB:		return GetButton(5, buttonAction, player);		// checked

                // trigger buttons
                case OuyaButton.LT: 	return GetButton(6, buttonAction, player);		// checked
                case OuyaButton.RT: 	return GetButton(7, buttonAction, player);		// checked

               	// stick buttons
                case OuyaButton.L3: 	return GetButton(8, buttonAction, player);		// checked
                case OuyaButton.R3: 	return GetButton(9, buttonAction, player);		// checked

                // center buttons
                case OuyaButton.SELECT: return GetButton(10, buttonAction, player);		// checked
                case OuyaButton.START: 	return GetButton(11, buttonAction, player);		// checked
                case OuyaButton.SYSTEM: return GetButton(12, buttonAction, player);		// checked

                // d-pad buttons
                case OuyaButton.DU:		return GetButton(13, buttonAction, player);		// checked
                case OuyaButton.DR:		return GetButton(14, buttonAction, player);		// checked
                case OuyaButton.DD:		return GetButton(15, buttonAction, player);		// checked
                case OuyaButton.DL:		return GetButton(16, buttonAction, player);		// checked

                // not defined do far
                default: return false;
                }
        #elif UNITY_EDITOR
                // the editor receives platform specific inputs which are not covered by the procompile macros
                // therefore the testing developer will have to set the Editor Working Platform
                // otherwise this code copies the data of the Windows and MacOSX platforms
                if (editorWorkPlatform == EditorWorkPlatform.MacOS) {
                    // MacOSX via standard Bluetooth connection
                    switch (button)
                    {
                   	// stick buttons
                    case OuyaButton.L3: 	return GetButton(1, buttonAction, player);		// checked
                    case OuyaButton.R3: 	return GetButton(2, buttonAction, player);		// checked

                    // center buttons
                    case OuyaButton.START: 	return GetButton(3, buttonAction, player);		// checked
                    case OuyaButton.SELECT: return GetButton(0, buttonAction, player);		// checked

                    // d-pad buttons
                    case OuyaButton.DU:		return GetButton(4, buttonAction, player);		// checked
                    case OuyaButton.DR:		return GetButton(5, buttonAction, player);		// checked
                    case OuyaButton.DD:		return GetButton(6, buttonAction, player);		// checked
                    case OuyaButton.DL:		return GetButton(7, buttonAction, player);		// checked

                    // trigger buttons
                    case OuyaButton.LT: 	return GetButton(8, buttonAction, player);		// checked
                    case OuyaButton.RT: 	return GetButton(9, buttonAction, player);		// checked

                    // shoulder buttons
                    case OuyaButton.LB:		return GetButton(10, buttonAction, player);		// checked
                    case OuyaButton.RB:		return GetButton(11, buttonAction, player);		// checked

                    // OUYA buttons
                    case OuyaButton.O:		return GetButton(14, buttonAction, player);		// checked
                    case OuyaButton.U:		return GetButton(15, buttonAction, player);		// checked
                    case OuyaButton.Y:		return GetButton(12, buttonAction, player);		// checked
                    case OuyaButton.A:		return GetButton(13, buttonAction, player);		// checked

                    // not defined do far
                    case OuyaButton.SYSTEM: return false;
                    default: return false;
                    }
                } else {
                    // Windows7 via USB and MotionInJoy driver
                    switch (button)
                    {
                    // OUYA buttons
                    case OuyaButton.O:		return GetButton(2, buttonAction, player);		// checked
                    case OuyaButton.U:		return GetButton(3, buttonAction, player);		// checked
                    case OuyaButton.Y:		return GetButton(0, buttonAction, player);		// checked
                    case OuyaButton.A:		return GetButton(1, buttonAction, player);		// checked

                    // shoulder buttons
                    case OuyaButton.LB:		return GetButton(4, buttonAction, player);		// checked
                    case OuyaButton.RB:		return GetButton(5, buttonAction, player);		// checked

                    // trigger buttons
                    case OuyaButton.LT: 	return GetButton(6, buttonAction, player);		// checked
                    case OuyaButton.RT: 	return GetButton(7, buttonAction, player);		// checked

                   	// stick buttons
                    case OuyaButton.L3: 	return GetButton(8, buttonAction, player);		// checked
                    case OuyaButton.R3: 	return GetButton(9, buttonAction, player);		// checked

                    // center buttons
                    case OuyaButton.SELECT: return GetButton(10, buttonAction, player);		// checked
                    case OuyaButton.START: 	return GetButton(11, buttonAction, player);		// checked
                    case OuyaButton.SYSTEM: return GetButton(12, buttonAction, player);		// checked

                    // d-pad buttons
                    case OuyaButton.DU:		return GetButton(13, buttonAction, player);		// checked
                    case OuyaButton.DR:		return GetButton(14, buttonAction, player);		// checked
                    case OuyaButton.DD:		return GetButton(15, buttonAction, player);		// checked
                    case OuyaButton.DL:		return GetButton(16, buttonAction, player);		// checked

                    default: return false;
                    }
                }
        #endif
        #if UNITY_EDITOR || UNITY_STANDALONE_OSX
            case OuyaControllerType.TattieBogle:
                // this is for the XBOX360 standard controller running on MacOSX using the TattieBogle driver
                // hopefully wireless XBOX controllers connected via Bluetooth have the same values
                // the d-pad has no pressure sensitivity but gives us button events
                // triggers provide only pressure sensitive axis output therefore
                // we need to use continious input scanning for managing Buttonup or ButtonDown events
                switch (button)
                {
                // shoulder buttons
                case OuyaButton.LB: 		return GetButton(13, buttonAction, player);		// checked
                case OuyaButton.RB: 		return GetButton(14, buttonAction, player);		// checked

                // OUYA buttons
                case OuyaButton.O: 			return GetButton(16, buttonAction, player);		// checked
                case OuyaButton.U:			return GetButton(18, buttonAction, player);		// checked
                case OuyaButton.Y: 			return GetButton(19, buttonAction, player);		// checked
                case OuyaButton.A: 			return GetButton(17, buttonAction, player);		// checked

                // stick buttons
                case OuyaButton.L3:			return GetButton(11, buttonAction, player);		// checked
                case OuyaButton.R3:			return GetButton(12, buttonAction, player);		// checked

                // center buttons
                case OuyaButton.SELECT:		return GetButton(10, buttonAction, player);		// checked
                case OuyaButton.START:		return GetButton(9, buttonAction, player);		// checked
                case OuyaButton.SYSTEM:		return GetButton(15, buttonAction, player);		// checked

                // d-pad buttons
                case OuyaButton.DU:			return GetButton(5, buttonAction, player);		// checked
                case OuyaButton.DD:			return GetButton(6, buttonAction, player);		// checked
                case OuyaButton.DL:			return GetButton(7, buttonAction, player);		// checked
                case OuyaButton.DR:			return GetButton(8, buttonAction, player);		// checked

                // trigger buttons
                // the triggers are axis and do not give out UP or DOWN events natively
                // we use button state management and continious scanning to provide these
                case OuyaButton.LT:	return GetCachedButtonEvent(button, buttonAction, playerIndex);
                case OuyaButton.RT: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                default: return false;
                }
        #endif
           		case OuyaControllerType.Unknown:
        #if !UNITY_EDITOR && UNITY_ANDROID
                // we hope to catch any unkown bluetooth controllers on Android here (wild card)
                // there can't be any testing for that as it's just a random try
                switch (button)
                {
                // ouya buttons
                case OuyaButton.O:		return GetButton(0, buttonAction, player);
                case OuyaButton.U:		return GetButton(3, buttonAction, player);
                case OuyaButton.Y:		return GetButton(4, buttonAction, player);
                case OuyaButton.A:		return GetButton(1, buttonAction, player);

                // shoulder buttons
                case OuyaButton.LB:		return GetButton(6, buttonAction, player);
                case OuyaButton.RB:		return GetButton(7, buttonAction, player);

                // stick buttons
                case OuyaButton.L3:		return GetButton(13, buttonAction, player);
                case OuyaButton.R3:		return GetButton(14, buttonAction, player);

                // d-pad buttons and trigger buttons
                // tese buttons are axis and do not give out UP or DOWN events natively
                // we use button state management and continious scanning to provide these
                case OuyaButton.DU: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                case OuyaButton.DD: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                case OuyaButton.DL: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                case OuyaButton.DR: return GetCachedButtonEvent(button, buttonAction, playerIndex);
                case OuyaButton.LT:	return GetCachedButtonEvent(button, buttonAction, playerIndex);
                case OuyaButton.RT:	return GetCachedButtonEvent(button, buttonAction, playerIndex);

                // not defined so far
                default: return false;
                }
        #endif
                break;
            }
        }
        /* SECURITY FALL THROUGH RETURN */
        return false;
    }
Пример #6
0
 public override void Reset()
 {
     playerNumber = 0;
     button       = 0;
 }
 public override void Reset()
 {
     playerNumber = 0;
     button = 0;
 }