Exemplo n.º 1
0
    public static float GetAxis(OuyaAxis axis, OuyaPlayer player)
    {
        /* for retreiving joystick axis values from mapped Unity Input
         */

        /* NULL SECURITY */
        // check if there is no joystick connected
        if (controllerCount == 0) return 0f;

        // check if there have more players than controllers
        // we consider that the array position is starting at 0 for player 1
        int playerIndex = (int)player - 1;
        if (playerIndex < 0 || playerIndex >= controllerCount) return 0f;

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

        /* GET MAPPED AXIS NAME */
        // prepare fields for storing the results
        string axisName = null; bool invert = false;

        // get the controller mapping for the player
        PlayerController playerController = playerControllers[playerIndex];
        // secure that we have found a mapping
        if (playerController == null) return 0f;
        else
        {
            /* JOYSTICKS */
            // get the axis name for the player controller
            switch (axis)
            {
                case OuyaAxis.LX: axisName = playerController.map_LX; invert = playerController.invert_LX; break;
                case OuyaAxis.LY: axisName = playerController.map_LY; invert = playerController.invert_LY; break;
                case OuyaAxis.RX: axisName = playerController.map_RX; invert = playerController.invert_RX; break;
                case OuyaAxis.RY: axisName = playerController.map_RY; invert = playerController.invert_RY; break;

                /* TRIGGERS & D-PAD */
                // the dpad and triggers are sometimes treated like an axis joystick
                // sometimes however it is just a set of buttons and the pressure senitivity is missing
                // this was observed for MacOS XBOX360 (TattieBogle) / Android Ouya / Android + MacOS PS3
                /* LT-TRIGGER */
                case OuyaAxis.LT: axisName = playerController.map_LT; invert = playerController.invert_LT;
                    // if the trigger is treated like a button we convert button press bool flags into axis values
                    if (axisName == null)
                    {
                        switch (mapType)
                        {
                            case OuyaMapType.MotionInJoy_WIN:
                            case OuyaMapType.PS3_ANDROID:
                            case OuyaMapType.PS3_OSX:
                                if (GetButton(OuyaButton.LT, player)) return 1f;
                                else return 0f;
                        }
                    }
                    break;
                /* RT-TRIGGER */
                case OuyaAxis.RT: axisName = playerController.map_RT; invert = playerController.invert_RT;
                    // if the trigger is treated like a button we convert button press bool flags into axis values
                    if (axisName == null)
                    {
                        switch (mapType)
                        {
                            case OuyaMapType.MotionInJoy_WIN:
                            case OuyaMapType.PS3_ANDROID:
                            case OuyaMapType.PS3_OSX:
                                if (GetButton(OuyaButton.RT, player)) return 1f;
                                else return 0f;
                        }
                    }
                    break;
                /* DX-AXIS */
                case OuyaAxis.DX: axisName = playerController.map_DX; invert = playerController.invert_DX;
                    // if the dpad is treated like a button we convert button press bool flags into axis values
                    if (axisName == null)
                    {
                        switch (mapType)
                        {
        #if !UNITY_EDITOR && UNITY_ANDROID
                        case OuyaMapType.Generic_ANDROID:
                        case OuyaMapType.Broadcom_ANDROID:
                        case OuyaMapType.Ouya_CONSOLE:
                        case OuyaMapType.PS3_ANDROID:
                        case OuyaMapType.XBOX360_ANDROID_wireless:
                        if (GetButton(OuyaButton.DL, player)) return -1f;
                        else if (GetButton(OuyaButton.DR, player)) return 1f;
                        break;
        #endif
        #if UNITY_EDITOR || UNITY_STANDALONE_WIN
                            case OuyaMapType.Ouya_WIN:
                            case OuyaMapType.MotionInJoy_WIN:
                                if (GetButton(OuyaButton.DL, player)) return -1f;
                                else if (GetButton(OuyaButton.DR, player)) return 1f;
                                break;
        #endif
        #if UNITY_EDITOR || UNITY_STANDALONE_OSX
                            case OuyaMapType.PS3_OSX:
                            case OuyaMapType.TattieBogle_OSX:
                                if (GetButton(OuyaButton.DL, player)) return -1f;
                                else if (GetButton(OuyaButton.DR, player)) return 1f;
                                break;
        #endif
                        }
                    } break;
                /* DY-AXIS */
                case OuyaAxis.DY: axisName = playerController.map_DY; invert = playerController.invert_DY;
                    // if the dpad is treated like a button we convert button press bool flags into axis values
                    if (axisName == null)
                    {
                        switch (mapType)
                        {
        #if !UNITY_EDITOR && UNITY_ANDROID
                        case OuyaMapType.Generic_ANDROID:
                        case OuyaMapType.Broadcom_ANDROID:
                        case OuyaMapType.Ouya_CONSOLE:
                        case OuyaMapType.PS3_ANDROID:
                        case OuyaMapType.XBOX360_ANDROID_wireless:
                        if (GetButton(OuyaButton.DD, player)) return -1f;
                        else if (GetButton(OuyaButton.DU, player)) return 1f;
                        break;
        #endif
        #if UNITY_EDITOR || UNITY_STANDALONE_WIN
                            case OuyaMapType.Ouya_WIN:
                            case OuyaMapType.MotionInJoy_WIN:
                                if (GetButton(OuyaButton.DD, player)) return -1f;
                                else if (GetButton(OuyaButton.DU, player)) return 1f;
                                break;
        #endif
        #if UNITY_EDITOR || UNITY_STANDALONE_OSX
                            case OuyaMapType.PS3_OSX:
                            case OuyaMapType.TattieBogle_OSX:
                                if (GetButton(OuyaButton.DD, player)) return -1f;
                                else if (GetButton(OuyaButton.DU, player)) return 1f;
                                break;
        #endif
                        }
                    } break;

                default: return 0f;
            }
        }
        /* FINAL SECURITY CHECK */
        // we return 0 if we didn't find a valid axis
        if (axisName == null) return 0f;

        /* TRIGGER AXIS RANGE MAPPING */
        if (axis == OuyaAxis.LT || axis == OuyaAxis.RT)
        {
            // some trigger axis need to be remapped inrange before we can return the Unity Input
            if (invert) return playerController.rangeMapTriggerAxis(-Input.GetAxisRaw(axisName), axis);
            else return playerController.rangeMapTriggerAxis(Input.GetAxisRaw(axisName), axis);
        }
        /* AXIS FLOAT RESULT FROM UNITY INPUT */
        if (invert) return -Input.GetAxisRaw(axisName);
        else return Input.GetAxisRaw(axisName);
    }
Exemplo n.º 2
0
        public float rangeMapTriggerAxis(float axisValue, OuyaAxis triggerAxis)
        {
            /* this remapping method allows to convert trigger axis values
             * we want to bring all trigger axis values into arange on 0 to 1
             * this is needed for the MacOSX XBOX360 driver which provides values from -1 to 1
             */
            // check if the trigger axis was initialized
            switch (triggerAxis)
            {
                case OuyaAxis.LT: if (!initAxisLT && axisValue != 0f) initAxisLT = true; break;
                case OuyaAxis.RT: if (!initAxisRT && axisValue != 0f) initAxisRT = true; break;
            }
            // we check if the controller we have need range mapping
            switch (mapType)
            {
            #if !UNITY_EDITOR && UNITY_ANDROID
                case OuyaMapType.Generic_ANDROID:
                case OuyaMapType.Broadcom_ANDROID:
                // remap values from range -1to1 onto range 0to1
                switch (triggerAxis) {
                    case OuyaAxis.LT:
                    // we only retrun a converted value if the trigger was initialized
                    // otherwise we would get out 0.5 initially without pressing the trigger
                    if (initAxisLT) return ((axisValue + 1) / 2f);
                    else return 0f;
                    case OuyaAxis.RT:
                    // we only retrun a converted value if the trigger was initialized
                    // otherwise we would get out 0.5 initially without pressing the trigger
                    if (initAxisRT) return ((axisValue + 1) / 2f);
                    else return 0f;
                    default: return 0f;
                }
            #endif

            #if UNITY_EDITOR || UNITY_STANDALONE_WIN
                case OuyaMapType.Ouya_WIN:
                    // remap values from range -1to1 onto range 0to1
                    switch (triggerAxis)
                    {
                        case OuyaAxis.LT:
                            // we only retrun a converted value if the trigger was initialized
                            // otherwise we would get out 0.5 initially without pressing the trigger
                            if (initAxisLT) return ((axisValue + 1) / 2f);
                            else return 0f;
                        case OuyaAxis.RT:
                            // we only retrun a converted value if the trigger was initialized
                            // otherwise we would get out 0.5 initially without pressing the trigger
                            if (initAxisRT) return ((axisValue + 1) / 2f);
                            else return 0f;
                        default: return 0f;
                    }
            #endif

            #if UNITY_EDITOR || UNITY_STANDALONE_OSX
                case OuyaMapType.TattieBogle_OSX:
                    // remap values from range -1to1 onto range 0to1
                    switch (triggerAxis)
                    {
                        case OuyaAxis.LT:
                            // we only retrun a converted value if the trigger was initialized
                            // otherwise we would get out 0.5 initially without pressing the trigger
                            if (initAxisLT) return ((axisValue + 1) / 2f);
                            else return 0f;
                        case OuyaAxis.RT:
                            // we only retrun a converted value if the trigger was initialized
                            // otherwise we would get out 0.5 initially without pressing the trigger
                            if (initAxisRT) return ((axisValue + 1) / 2f);
                            else return 0f;
                        default: return 0f;
                    }
            #endif

                default:
                    // just retrun the value without changes
                    return axisValue;
            }
        }
Exemplo n.º 3
0
 public string getAxisID(OuyaAxis ouyaButton)
 {
     /* returns the cached axis ID called for
      */
     switch (ouyaButton)
     {
         case OuyaAxis.LX: return map_LX;
         case OuyaAxis.LY: return map_LY;
         case OuyaAxis.RX: return map_RX;
         case OuyaAxis.RY: return map_RY;
         case OuyaAxis.LT: return map_LT;
         case OuyaAxis.RT: return map_RT;
         case OuyaAxis.DX: return map_DX;
         case OuyaAxis.DY: return map_DY;
         default: return null;
     }
 }
Exemplo n.º 4
0
 public bool getAxisInvert(OuyaAxis ouyaButton)
 {
     /* returns a flag indicating whether the axis needs inversion
      */
     switch (ouyaButton)
     {
         case OuyaAxis.LX: return invert_LX;
         case OuyaAxis.LY: return invert_LY;
         case OuyaAxis.RX: return invert_RX;
         case OuyaAxis.RY: return invert_RY;
         case OuyaAxis.LT: return invert_LT;
         case OuyaAxis.RT: return invert_RT;
         case OuyaAxis.DX: return invert_DX;
         case OuyaAxis.DY: return invert_DY;
         default: return false;
     }
 }
Exemplo n.º 5
0
    public static float GetAxis(OuyaAxis axis, OuyaPlayer player)
    {
        /* for retreiving joystick axis values from mapped Unity Input
         */

        /* NULL SECURITY */
        // check if there is no joystick connected
        if (controllerCount == 0) return 0f;

        // check if there have more players than controllers
        // we consider that the array position is starting at 0 for player 1
        int playerIndex = (int)player - 1;
        if (playerIndex < 0 || playerIndex >= controllerCount) return 0f;

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

        /* GET MAPPED AXIS NAME */
        // prepare fields for storing the results
        string axisName = null; bool invert = false;

        // get the controller mapping for the player
        PlayerController playerController = playerControllers[playerIndex];
        // secure that we have found a mapping
        if (playerController == null) return 0f;
        else
        {
            /* JOYSTICKS */
            // get the axis name for the player controller
            switch (axis) {
            case OuyaAxis.LX: axisName = playerController.map_LX; invert = playerController.invert_LX; break;
           	case OuyaAxis.LY: axisName = playerController.map_LY; invert = playerController.invert_LY; break;
            case OuyaAxis.RX: axisName = playerController.map_RX; invert = playerController.invert_RX; break;
           	case OuyaAxis.RY: axisName = playerController.map_RY; invert = playerController.invert_RY; break;

            /* TRIGGERS & D-PAD */
            // the dpad and triggers are sometimes treated like an axis joystick
            // sometimes however it is just a set of buttons and the pressure senitivity is missing
            // this was observed for MacOS XBOX360 (TattieBogle) / Android Ouya / Android + MacOS PS3
            /* LT-TRIGGER */
            case OuyaAxis.LT: axisName = playerController.map_LT; invert = playerController.invert_LT;
                // if the trigger is treated like a button we convert button press bool flags into axis values
                if (axisName == null)
                {
                    switch (controllerType) {
                    case OuyaControllerType.PS3:
                        if (GetButton(8, ButtonAction.Pressed, player)) return 1f; else return 0f;
                    }
                }
                break;
            /* RT-TRIGGER */
            case OuyaAxis.RT: axisName = playerController.map_RT; invert = playerController.invert_RT;
                // if the trigger is treated like a button we convert button press bool flags into axis values
                if (axisName == null)
                {
                    switch (controllerType) {
                    case OuyaControllerType.PS3:
                        if (GetButton(9, ButtonAction.Pressed, player)) return 1f; else return 0f;
                    }
                }
                break;
            /* DX-AXIS */
            case OuyaAxis.DX: axisName = playerController.map_DX; invert = playerController.invert_DX;
                // if the dpad is treated like a button we convert button press bool flags into axis values
                if (axisName == null)
                {
                    switch (controllerType) {
                    case OuyaControllerType.Ouya:
                        if (GetButton(10, ButtonAction.Pressed, player)) return -1f;
                        else if (GetButton(11, ButtonAction.Pressed, player)) return 1f;
                        break;
                    case OuyaControllerType.PS3:
        #if !UNITY_EDITOR && UNITY_ANDROID
                        if (GetButton(7, ButtonAction.Pressed, player)) return -1f;
                        else if (GetButton(5, ButtonAction.Pressed, player)) return 1f;
        #elif !UNITY_EDITOR && UNITY_STANDALONE_OSX
                        if (GetButton(7, ButtonAction.Pressed, player)) return -1f;
                        else if (GetButton(5, ButtonAction.Pressed, player)) return 1f;
        #elif !UNITY_EDITOR && UNITY_STANDALONE_WIN
                        if (GetButton(16, ButtonAction.Pressed, player)) return -1f;
                        else if (GetButton(14, ButtonAction.Pressed, player)) return 1f;
        #elif UNITY_EDITOR
                        // in the editor we have to set on which platform we are working
                        // different editor working environments are not covered by Unity's macros
                        if (editorWorkPlatform == EditorWorkPlatform.MacOS)
                        {
                            if (GetButton(7, ButtonAction.Pressed, player)) return -1f;
                            else if (GetButton(5, ButtonAction.Pressed, player)) return 1f;
                        }
                        else {
                            if (GetButton(16, ButtonAction.Pressed, player)) return -1f;
                            else if (GetButton(14, ButtonAction.Pressed, player)) return 1f;
                        }
        #endif
                        break;
        #if UNITY_EDITOR || UNITY_STANDALONE_OSX
                    case OuyaControllerType.TattieBogle:
                        if (GetButton(7, ButtonAction.Pressed, player)) return -1f;
                        else if (GetButton(8, ButtonAction.Pressed, player)) return 1f;
                        break;
        #endif
                    }
                } break;
            /* DY-AXIS */
            case OuyaAxis.DY: axisName = playerController.map_DY; invert = playerController.invert_DY;
                // if the dpad is treated like a button we convert button press bool flags into axis values
                if (axisName == null)
                {
                    switch (controllerType) {
                    case OuyaControllerType.Ouya:
                        if (GetButton(8, ButtonAction.Pressed, player)) return 1f;
                        else if (GetButton(9, ButtonAction.Pressed, player)) return -1f;
                        break;
                    case OuyaControllerType.PS3:
        #if !UNITY_EDITOR && UNITY_ANDROID
                        if (GetButton(6, ButtonAction.Pressed, player)) return -1f;
                        else if (GetButton(4, ButtonAction.Pressed, player)) return 1f;
        #elif !UNITY_EDITOR && UNITY_STANDALONE_OSX
                        if (GetButton(6, ButtonAction.Pressed, player)) return -1f;
                        else if (GetButton(4, ButtonAction.Pressed, player)) return 1f;
        #elif !UNITY_EDITOR && UNITY_STANDALONE_WIN
                        if (GetButton(15, ButtonAction.Pressed, player)) return -1f;
                        else if (GetButton(16, ButtonAction.Pressed, player)) return 1f;
        #elif UNITY_EDITOR
                        // in the editor we have to set on which platform we are working (Win or MacOS)
                        // different editor working environments are not covered by Unity's macros
                        if (editorWorkPlatform == EditorWorkPlatform.MacOS)
                        {
                            if (GetButton(6, ButtonAction.Pressed, player)) return -1f;
                            else if (GetButton(4, ButtonAction.Pressed, player)) return 1f;
                        }
                        else {
                            if (GetButton(15, ButtonAction.Pressed, player)) return -1f;
                            else if (GetButton(16, ButtonAction.Pressed, player)) return 1f;
                        }
        #endif
                        break;
        #if UNITY_EDITOR || UNITY_STANDALONE_OSX
                    case OuyaControllerType.TattieBogle:
                        if (GetButton(5, ButtonAction.Pressed, player)) return 1f;
                        else if (GetButton(6, ButtonAction.Pressed, player)) return -1f;
                        break;
        #endif
                    }
                } break;

            default: return 0f;
            }
        }
        /* FINAL SECURITY CHECK */
        // we return 0 if we didn't find a valid axis
        if (axisName == null) return 0f;

        /* TRIGGER AXIS RANGE MAPPING */
        if (axis == OuyaAxis.LT || axis == OuyaAxis.RT) {
            // some trigger axis need to be remapped inrange before we can return the Unity Input
            if (invert) return playerController.rangeMapTriggerAxis(-Input.GetAxisRaw(axisName), axis);
            else return playerController.rangeMapTriggerAxis(Input.GetAxisRaw(axisName), axis);
        }
        /* AXIS FLOAT RESULT FROM UNITY INPUT */
        if (invert) return -Input.GetAxisRaw(axisName);
        else return Input.GetAxisRaw(axisName);
    }