NEW OuyaInput Controller Framework (simple, fast, with documantation)

ClarkGameClarkGame Posts: 74Member
edited July 2013 in Unity on OUYA
Hey OUYA Devs,
as we are now done with our E3 stuff, I found some time to improve on the OuyaInput Framework that I was proposing in "Controller Solutions – (Con)Tribute to Tim".

This new script is (I hope) a big leap forward to a simple to use, powerfull and performance optimized cross-platform controller solution. I have decided to open up a new thread here to have a fresh start. Feel free to use this in your projects and please feedback about your experience with this approach. I am trying to improve it based on your comments. PLEASE read the documentation provided in this package. The stuff below can best be downloaded via right-click:

OuyaInput Downloads: UPDATED to Version_0.07

Complete Package
Documentation
Core Input Access
Input Tester (GUI overlay)
InputHandler Example C#
InputHandler Example JavaScript
Important Project Settings

Always the NEWEST on GIT

Links in this post will be updated with new versions.

Cheers,
Matthias CLARK / GoldenTricycle
our GAME >> CLARK
Post edited by ClarkGame on
Matthias Titze
CLARK

by
GoldenTricycle


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


«13456710

Comments

  • ClarkGameClarkGame Posts: 74Member
    Added a GIT repository for commiting change proposals:
    GIT OuyaInputFramework

    I would still recommend the standard download as I did some reformatting for GIT which looks better there but awfull in Mono Develop.
    Matthias Titze
    CLARK

    by
    GoldenTricycle


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


  • EMcNeillEMcNeill Posts: 47Member
    Wow, thanks a lot for setting this up!

    I've implemented it in my own game, but I'm having an issue when making a PC standalone version. It's not recognizing and switching to new controllers when I plug one in or out mid-game. Oddly enough, it works perfectly when I play in the editor. Any idea what might be causing that?
  • tgraupmanntgraupmann Posts: 2,869Administrator, Team OUYA
    Start with Input.GetJoystickNames() as a Unity standalone is it recognizing the names?
    ~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
    Hey,
    I need a few informations for checking this issue:
    1. What type of controller are you using?
    2. On which platform are you developing?
    3. When you just put in the InputTester script in your scene, which controller name and type is printed on the GUI?
    4. Are you using single or multiplayer.

    I discovered one issue with the XBOX360 controller today. Somehow this controller seems to switch the player channel when unplugged and reconnected. This can be seen on the center button where the green quarter-ring indicating the player will shift.

    When the player channel switches you won't get input for the player you call in your methods. Let's say you ask for player one's input and the controller suddenly decides to switch to player four...

    Can you confirm this from your experience – or do we have another case?
    I thought this might be a driver issue. If this is the case we could develop a work around with OuyaInput dynamically switching the channels, giving back the correct player which then could be used via a variable to get the correct input.
    Matthias Titze
    CLARK

    by
    GoldenTricycle


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


  • ClarkGameClarkGame Posts: 74Member
    More Questions:
    How much time do you let pass between the unplug and reconnect?
    Are you switching controller types?
    Matthias Titze
    CLARK

    by
    GoldenTricycle


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


  • ClarkGameClarkGame Posts: 74Member
    I double checked, discovered some logic bugs and fixed them.
    As I have no controller here now I couldn't test the result now.
    I will do that tomorrow. However I would be intersted if this version works and solved your issues:
    OuyaInput_v0.02_alpha
    Matthias Titze
    CLARK

    by
    GoldenTricycle


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


  • agentsmith666agentsmith666 Posts: 1Member
    edited June 2013

    Post edited by agentsmith666 on
  • EMcNeillEMcNeill Posts: 47Member
    edited June 2013
    I tried Tim's suggestion first and, sure enough, I found that the problem lies there, not necessarily with OuyaInput.cs. In the editor, plugging in and unplugging the controller works perfectly. On a standalone executable, it will react correctly when I unplug a controller, but it will never detect a controller that's plugged in while the game is running. Any suggestions for what I should try? If the problem is with Unity's Input class, I'm really not sure where to go.

    EDIT: Actually, could someone else test this in a standalone Windows exported game? I wonder if this is a Unity-wide problem or just on my machine.

    For the sake of compleness, here's the rest of my info:
    - I'm using a wireless Xbox 360 controller
    - On Windows
    - InputTester shows the usual Xbox 360 wireless receiver string, but shows the same issue as detailed above (i.e. does not detect a hot-plugged controller)
    - Testing with singleplayer for now
    - I'm giving it plenty of time, way more than the requisite 3 seconds
    - No, I'm not switching between types of controllers
    Post edited by EMcNeill on
  • ClarkGameClarkGame Posts: 74Member
    The problem is buried on the level of the Unity engine. There is no way to solve it without tapping into the Unity source code. Unity's joystick recognition has some serious issues with hot-plugging which are discussed this Unity forum post I found:

    Relevant Unity Forum Discussion

    OuyaInput.cs wraps access methods of Unity.Input (best performance and convenience). The only Unity.Input method to get to know the plugged controllers is: Unity.Input.GetControllerNames(). This returns a string array with the names that Unity considers to be joystick-ids. However on the lower engine level this method does not really poll joysticks reliably. This was discussed and also bug-reported to Unity but never fixed. So, as we can't accces the engine source for now, we have to live with two issues (I think this is mostly for the Wndows standalone player):

    1. Hot-plugging will not always discover joysticks correctly (I hat no problem with hotplugging a PS3 on MacOSX, but hotplugging a XBOX360 USB on Windows did not work).

    2. Sometimes (not often) Unity will mess up the joystick order. This means that ids in the array may not have the correct array index respective to the joystick axis channels. Mapping will mess up completely then. Again, no help.

    Unfortunetaly this is as good as it gets. (Well, if someone writes a complete C++ joystick plugin to replace Unity.Input completely...there would be a chance).

    Matthias Titze
    CLARK

    by
    GoldenTricycle


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


  • ClarkGameClarkGame Posts: 74Member
    Hah, I found this snipped in another forum:

    Hi there
    I've been bashing my head on the wall (well not literally, but still...) trying to figure this one out.
    I finally worked it out so I thought I'd put the answer here to help anyone else who tries Googling for this.

    I'm pretty sure it's a bug with the "Resolution Dialog" before your game runs. If you go to File -> Build Settings -> Player Settings -> PC, Mac & Linux Standalone and change "Display Resolution Dialog" to "Disabled" then even if you disconnect/reconnect the pad it should still work.

    Matthias Titze
    CLARK

    by
    GoldenTricycle


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


  • ClarkGameClarkGame Posts: 74Member
    The links at the top of this discussions are now updated to Version_0.02. There should be some important improvements and fixes.
    Matthias Titze
    CLARK

    by
    GoldenTricycle


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


  • EMcNeillEMcNeill Posts: 47Member
    Hmm, I definitely want to keep my Resolution Dialog. I suppose I'll just have to live with it.
  • JaegerJaeger Posts: 26Member
    I followed the instructions and am getting an exception in the OuyaGameObject...

    UnityException: Input Axis Horizontal is not setup.
     To change the input settings use: Edit -> Project Settings -> Input
    OuyaGameObject.getDpadPress (System.String V, System.String H, .Device device) (at Assets/Ouya/SDK/Scripts/OuyaGameObject.cs:2025)
    OuyaGameObject.Update () (at Assets/Ouya/SDK/Scripts/OuyaGameObject.cs:1886)

    What did I do wrong?  Thanks.

  • JaegerJaeger Posts: 26Member
    Might have answered my own question.  I unchecked "Use Legacy Input" on the OuyaGameObject.  No more error!
  • tgraupmanntgraupmann Posts: 2,869Administrator, Team OUYA
    edited June 2013
    Looks like you called Input.GetAxis("Horizontal") and that's not how it works. The names are setup like

    "Joystick1Axis1". And yes Use Legacy Input should be off.
    Post edited by tgraupmann on
    ~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
    edited June 2013
    Jaeger said:
    Might have answered my own question.  I unchecked "Use Legacy Input" on the OuyaGameObject.  No more error!
    Yes, UNCHECK "Use Legacy Input" in our OuyaGameObject. This is absolutely vital – sorry I forgot to add this to the documentation (will do). Whenever you get these "UnityException: Input Axis "XX" is not setup."- errors, there are basically three mistakes I can think of:

    1. You use the wrong InputManager.asset (sets Edit >> PrjoctSettings >> Input where you should now find about 100+ defined joystick axis with names like "Joystick1Axis1".

    2. You indirectly call for an axis that is not defined anymore. That happens, when you use Legacy Input. I killed every axis setting that was only connected to legacy stuff and cleaned up. Legacy Input sometimes accesses axes via the wrapped Unity.Input.GetAxis() but doesn't know the new generic string ids of the respective axes channels.

    3. You manually call Unity.Input.GetAxis() yourself. This should not be done. OuyaInput.GetAxis() wraps this method and adds some vital ids to do all the generic mapping and axis channel sorting.
    Post edited by ClarkGame on
    Matthias Titze
    CLARK

    by
    GoldenTricycle


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


  • tgraupmanntgraupmann Posts: 2,869Administrator, Team OUYA
    It's probably time we mark the UseLegacyInput=false by default in the OuyaGameObject.
    ~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
    Yup, guess it could be good time to discard the legacy stuff (maybe also clean up the examples?).
    Updated all Links to OuyaInput Version_0.03.

    Changelog:
    – some minor bug fixes
    – all console warnings fixed
    – new utility access methods (GetJoystickAngle())
    – updated documentation
    – legacy input warning
    Matthias Titze
    CLARK

    by
    GoldenTricycle


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


  • tgraupmanntgraupmann Posts: 2,869Administrator, Team OUYA
    edited June 2013
    I can add a notification alert if UseLegacy is true. Good point!
    Post edited by tgraupmann on
    ~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].
  • JaegerJaeger Posts: 26Member
    The code that was mad about the Horizontal axis was the OuyaGameObject.  :-)  I'll try with all the latest code.
  • ClarkGameClarkGame Posts: 74Member
    Updated links to OuyaInput to Version_0.04

    Changelog:
    – added support for Ouya Controller on Windows 8 (should also work on Win 7)
    – updated documentation and package accordingly
    Matthias Titze
    CLARK

    by
    GoldenTricycle


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


  • AceriaAceria Posts: 8Member
    Is it possible to use the "home" button on the ouya from within your class? I've been using it (fantastic piece of work by the way) but cannot find this anywhere in the documentation (or code for that matter). Am I missing something or is it just not possible with your class?
  • ClarkGameClarkGame Posts: 74Member
    The OUYA Home Button is not really accessable and should not be.
    On the OUYA console it will allways bring you back to the main OUYA menu screen.
    This is part of the OUYA SDK and should always be left as it is.
    The button shows the same behaviour when using OuyaInput and porting to the OUYA.
    Matthias Titze
    CLARK

    by
    GoldenTricycle


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


  • tgraupmanntgraupmann Posts: 2,869Administrator, Team OUYA
    Actually there's a listener for a single press of the system button.

    It's OuyaSDK.IMenuButtonUpListener.

    ~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
    That's what I meant with being part of the OUYA SDK. As this behaviour is very system specific and serves a specific function there, I was going for leaving it out of the cross.platform controller handler. It serves to fire Ouya specific events and is connected to the Ouya application lifecycle. Pretty much the same as the Android back or home capacitive buttons on tablets or smartphones.

    So better leave it to this event listener, right?
    Matthias Titze
    CLARK

    by
    GoldenTricycle


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


  • ClarkGameClarkGame Posts: 74Member
    Hm, I wonder wether this event listeners should find there way into the documentation. However I didn't get my hands dirty with these yet and do not really now what purpose they could serve in an Unity application – ANY TIPS?
    Matthias Titze
    CLARK

    by
    GoldenTricycle


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


  • tgraupmanntgraupmann Posts: 2,869Administrator, Team OUYA
    Yes the controller documentation is a bit dusty, I need to gut that part...
    ~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].
  • pyscho2daypyscho2day Posts: 36Member
    Please Please Please gut the controller docs,  I have been looking at stuff as i am about ready to setup my controllers and its confusing where there are multiple variants on how to do things.  I think i know what to do and will find out when I get home tonight as I am unable to test while I am at work.

    Also a huge Thanks to both Tim and Matthias.  With out the work Tim has done and the additions from Matthias i would have a much bigger headache learning all of what would have to be done. 
  • RadiangamesRadiangames Posts: 12Member
    Just wanted to say thanks for this!  Very nice and straightforward instructions, though I added OUYASDK-Core.unitypackage to my project first.  Think that works better since there's less stuff to screw up.

    Haven't tried an OUYA controller on PC, but 360 controller works on PC and console, and OUYA controller obviously works on the console too.  Will let you know if I run into any problems.

    This seems good enough to mention on the OUYA-Unity doc page (if it is, I missed it).
  • JaegerJaeger Posts: 26Member
    I like this controller library.  So far, it's made life easier.  However, how do I use it (properly) with other libraries?  Specifically, NGUI.  I managed to get the left/right wired up so I can select buttons in my GUI but I don't know what to use for joystick buttons.
Sign In or Register to comment.