Controller Mapping ?

THUGZ357THUGZ357 Posts: 6Member
edited May 2013 in Unity on OUYA
do i need to edit my FPSController scrip. For the player in my game to work on the ouya controller?
Post edited by THUGZ357 on

Comments

  • tgraupmanntgraupmann Posts: 2,869Administrator, Team OUYA
    You'll want to import my input mappings and reopen the project. You can continue to use the Input API, but the axis names that I used will likely be different. So there will be a small change. Take a look at ShowUnityInput.cs and take a close look at the example. It should be pretty straightforward.
    ~Tim Graupmann
    OUYA Inc | Android Developer
    Skype: tgraupmann_prey

    http://github.com/ouya/docs
    http://github.com/ouya/ouya-sdk-examples

    Check out the latest docs for your game engine: [setup] [adobe air] [android] [clickteam fusion] [construct 2] [corona] [libGDX] [game maker] [html5] [marmalade] [monogame] [unity] [unreal]

    Use caution when setting [persistent wireless mode].
  • ClarkGameClarkGame Posts: 74Member
    I did tow input handlers: One for Unity testing (PC / Mac) and one for the OUYA.
    For the Ouya you will have imported the OUYA SDK scripts.
    Access methods of the OuyaInputManager script. They are pretty much the same as the ones the Unity framework provides, but the methods access the OUYA input signals that come from their JAVA JNI framework. Added some code here to give an example (just a quick copy, not a full framework). It's just to demonstarte the similarities.

    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;

    public class InputHandlerOuya : InputHandlerController,
         OuyaSDK.IPauseListener, OuyaSDK.IResumeListener,
        OuyaSDK.IMenuAppearingListener
    {
        private OuyaSDK.OuyaPlayer player = OuyaSDK.OuyaPlayer.player1;
       
        /* -----------------------------------------------------------------------------------
         * INITIALIZATION
         */
       
        internal void Awake()
        {
            // register the event this class as a listener to Ouya's menu events
            // that's why we implemented the listener interfaces
            OuyaSDK.registerMenuAppearingListener(this);
            OuyaSDK.registerPauseListener(this);
            OuyaSDK.registerResumeListener(this);
           
            // add this class for receiving button events
            OuyaInputManager.OuyaButtonEvent.addButtonEventListener(HandleButtonEvent);
        }
       
        internal void OnDestroy()
        {
            // unregister this class from listening to Ouya's menu events
            OuyaSDK.unregisterMenuAppearingListener(this);
            OuyaSDK.unregisterPauseListener(this);
            OuyaSDK.unregisterResumeListener(this);
           
            // also stop listening to button events
            OuyaInputManager.OuyaButtonEvent.removeButtonEventListener(HandleButtonEvent);
            OuyaInputManager.initKeyStates();
        }
       
        /* -----------------------------------------------------------------------------------
         * OUYA EVENTS INTERFACE
         */
       
        public void OuyaMenuAppearing()
        {
            Debug.Log("OUYA called MENU");
        }

        public void OuyaOnPause()
        {
            Debug.Log("OUYA called PAUSE");
        }

        public void OuyaOnResume()
        {
            Debug.Log("OUYA called RESUME");
        }
       
        /* -----------------------------------------------------------------------------------
         * OUYA BUTTOIN EVENT
         */
       
        internal void HandleButtonEvent(OuyaSDK.OuyaPlayer p, OuyaSDK.KeyEnum b, OuyaSDK.InputAction bs)
        {
            // ToDo Implement any button event actions – not needed in this
        }
       
        /* -----------------------------------------------------------------------------------
         * PRIVATE PROCEDURES
         */
       
        protected override bool getInteractDown() {
            /* method stump for getting raw button data
             */
            // prepare a flag for return
            bool buttonDown = false;
            // check multiple buttons
            if (OuyaInputManager.GetButtonDown("O", player)
                || OuyaInputManager.GetButtonDown("U", player))
            {
                buttonDown = true;
            }
            // return the result
            return buttonDown;
        }
       
        protected override float getRSAxis() {
            /* implemented method for a helper getting the raw joystick data
             */
           
            /* CHECK R-STICK INPUT */
            //get joystick points and calculate deadzone
            Vector2 point = convertRawJoystickCoordinates(
                OuyaInputManager.GetAxis("RX", player), -OuyaInputManager.GetAxis("RY", player), 0.25f);
            // get the input value for the correct axis
            float inputValue = point.x;
            // return the result
            return inputValue;
        }
       
        protected override Vector2 getLSAxis() {
            /* implemented method for a helper getting the raw joystick data
             */
           
            /* CHECK L-STICK INPUT */
            //get joystick points and calculate deadzone
            Vector2 inputPoint = convertRawJoystickCoordinates(
                OuyaInputManager.GetAxis("LX", player), -OuyaInputManager.GetAxis("LY", player), 0.25f);
            // return the result
            return inputPoint;
        }
           
        private Vector2 convertRawJoystickCoordinates(float x, float y, float deadRadius) {
            /* helper method to convert joystick axis values into a handy vector 2D
             * also caps values inside the deadzone (below minimum radius)
             */
           
            // we just put the float into a 2D vector
            Vector2 result = new Vector2(x, y);
           
            // we require minimum values – lower values will be cut off (deadzone)
            bool isInDeadzone = deadzoneTest(x, y, deadRadius);
            if (isInDeadzone) {result.x = 0f; result.y = 0f;}
           
            // return vector
            return result;
        }

        private bool deadzoneTest(float x, float y, float radius) {
            /* helper method doing the deadzone calculation
             * just nicely packaged piece of basic math
             */
            float distance = Mathf.Sqrt((x * x) + (y * y));
            return distance < radius;
        }
    Matthias Titze
    CLARK

    by
    GoldenTricycle


    Developer for CLARK / GoldenTricycle
    Developer of OuyaInput Framework >> GIT


  • ClarkGameClarkGame Posts: 74Member
    Be aware the the GetButtonDown() is not implemented well in their framework and does not work like Unity's ButtonDown getter. I believe they just give you the value of GetButton(). So that is not really just for the event (the actual first pressing down) but for the whole state (player holding down). So either you handle this (I set bool flags that I consumed when the input was used) or you use event listeners and the method HandleButtonEvent in the example above.
    Matthias Titze
    CLARK

    by
    GoldenTricycle


    Developer for CLARK / GoldenTricycle
    Developer of OuyaInput Framework >> GIT


  • tgraupmanntgraupmann Posts: 2,869Administrator, Team OUYA
    Right but that's the legacy input. If you follow ShowUnityInput you can use the Unity Input API normally.
    ~Tim Graupmann
    OUYA Inc | Android Developer
    Skype: tgraupmann_prey

    http://github.com/ouya/docs
    http://github.com/ouya/ouya-sdk-examples

    Check out the latest docs for your game engine: [setup] [adobe air] [android] [clickteam fusion] [construct 2] [corona] [libGDX] [game maker] [html5] [marmalade] [monogame] [unity] [unreal]

    Use caution when setting [persistent wireless mode].
  • THUGZ357THUGZ357 Posts: 6Member
    am using the ShowUnityInput but when i press say dpad up it does dpad left where do i need to edit ?
  • tgraupmanntgraupmann Posts: 2,869Administrator, Team OUYA
    If you are on Unity 4.X there's an import bug. So inspect the ShowUnityInput gameobject and in the mesh references, double check that all the virtual controller mappings are correct.

    And then you should be able to see the controller name on the right.

    The mappings are based on the controller name, and for the example are mapped in OuyaExampleCommon.cs
    ~Tim Graupmann
    OUYA Inc | Android Developer
    Skype: tgraupmann_prey

    http://github.com/ouya/docs
    http://github.com/ouya/ouya-sdk-examples

    Check out the latest docs for your game engine: [setup] [adobe air] [android] [clickteam fusion] [construct 2] [corona] [libGDX] [game maker] [html5] [marmalade] [monogame] [unity] [unreal]

    Use caution when setting [persistent wireless mode].
  • THUGZ357THUGZ357 Posts: 6Member
    If you are on Unity 4.X there's an import bug. So inspect the ShowUnityInput gameobject and in the mesh references, double check that all the virtual controller mappings are correct.

    And then you should be able to see the controller name on the right.

    The mappings are based on the controller name, and for the example are mapped in OuyaExampleCommon.cs
    Thanks :) 
  • ClarkGameClarkGame Posts: 74Member
    Right but that's the legacy input. If you follow ShowUnityInput you can use the Unity Input API normally.
    Thx, Tim. I will dive into that. However the new input was difficult to set up. It didn't really recognice my XBOX360 controller with that messy MacOSX driver. Console doesn't show any controller ID. Any tips obout that. Works with my Unity mappings, but OuyaSDK doesn't see it.
    Matthias Titze
    CLARK

    by
    GoldenTricycle


    Developer for CLARK / GoldenTricycle
    Developer of OuyaInput Framework >> GIT


  • tgraupmanntgraupmann Posts: 2,869Administrator, Team OUYA
    Yeah I've emailed the tattooboggie driver maker about the driver not providing a controller name.

    If you grab the latest for github I fixed the mappings and check for the blank controller name.

    The tattooboggie driver is open source so we could always build it and insert a joystick name.
    ~Tim Graupmann
    OUYA Inc | Android Developer
    Skype: tgraupmann_prey

    http://github.com/ouya/docs
    http://github.com/ouya/ouya-sdk-examples

    Check out the latest docs for your game engine: [setup] [adobe air] [android] [clickteam fusion] [construct 2] [corona] [libGDX] [game maker] [html5] [marmalade] [monogame] [unity] [unreal]

    Use caution when setting [persistent wireless mode].
Sign In or Register to comment.