Tim I could use a little more hand-holding on this... I've been developing my game using the standard Unity input stuff, and as of tonight got it up and running on the dev kit. I did this by importing OuyaSDK.unitypackage into my existing project.
Everything went pretty smoothly, except I have no input - I'm not getting any events. Which makes sense as I haven't done anything to set it up!
What I want to do is get get the Unity controller talking to my existing input code as simply as possible. I'm getting a little confused with the various wrappers/managers, so I'm not sure what is the minimal set of changes I can make to get things working.
My primary goal is evaluating perf on Ouya, so I'm trying not to get to caught up in re-writing my input stuff right now (I don't mind doing it later if necessary).
tl;dr: What's the easiest way to simply pipe the Ouya controller though to my existing input code?
EDIT: I realize that's what you're trying to tell me in your previous post... I'm just not 100% clear on how to apply what you've written there! I'm pretty dumb =]
error CS0426: The nested type `InputButtonListener' does not exist in the type `OuyaSDK' error CS1502: The best overloaded method match for `OuyaSDK.registerInputButtonListener(OuyaSDK.InputButtonListener<OuyaSDK.InputButtonEvent>)' has some invalid arguments Assets/Global/Script/Vehicle.cs(78,25): error CS1503: Argument `#1' cannot convert `object' expression to type `OuyaSDK.InputButtonListener<OuyaSDK.InputButtonEvent>'
Not sure I understand... I'm saying that the version of OuyaShowController.cs that works in the same app calls new differently (i.e., it includes a <type> that your example above doesn't).
Sorry for the confusion. The OuyaShowController.cs example included in the package is one way to capture input events. There's an alternate way included and not referenced, which is a way that wraps the Unity input. Here is an (OuyaControllerExample2) example of passing the input events to a wrapper to access just like the Unity input API.
using System;
using System.Collections.Generic;
using UnityEngine;
public class OuyaControllerExample2 : MonoBehaviour
{
///
/// This is your assigned developer id
///
private const string DEVELOPER_ID = "310a8f51-4d6e-4ae5-bda0-b93878e5f5d0";
void Awake()
{
try
{
OuyaSDK.initialize(DEVELOPER_ID);
OuyaSDK.registerInputButtonListener(new OuyaSDK.InputButtonListener()
{
onSuccess = (OuyaSDK.InputButtonEvent inputEvent) =>
{
OuyaInputManager.HandleButtonEvent(inputEvent);
},
onFailure = (int errorCode, string errorMessage) =>
{
}
});
OuyaSDK.registerInputAxisListener(new OuyaSDK.InputAxisListener()
{
onSuccess = (OuyaSDK.InputAxisEvent inputEvent) =>
{
OuyaInputManager.HandleAxisEvent(inputEvent);
},
onFailure = (int errorCode, string errorMessage) =>
{
}
});
}
catch (System.Exception ex)
{
Debug.LogError(string.Format("Awake exception={0}", ex));
}
}
}
...but these events don't trigger. What do I need to change? The "Input" part or the "Fire2" part?
EDIT: Amusingly, the only thing I can get to trigger my existing code is a double tap on the track pad... no idea why that would be the case. That is sending a "Fire1" message.
///
/// Wrap Unity's method
///
///
///
public static bool GetButton(string inputName)
{
#if UNITY_ANDROID
switch (inputName)
{
case "SYS": //arbitrary name and mapping
return m_buttonSystem;
case "DPC": //arbitrary name and mapping
return m_buttonDPadCenter;
case "DPD": //arbitrary name and mapping
return m_buttonDPadDown;
case "DPL": //arbitrary name and mapping
return m_buttonDPadLeft;
case "DPR": //arbitrary name and mapping
return m_buttonDPadRight;
case "DPU": //arbitrary name and mapping
return m_buttonDPadUp;
case "O": //arbitrary name and mapping
return m_buttonO;
case "U": //arbitrary name and mapping
return m_buttonU;
case "Y": //arbitrary name and mapping
return m_buttonY;
case "A": //arbitrary name and mapping
return m_buttonA;
case "LT": //arbitrary name and mapping
return m_buttonLT;
case "RT": //arbitrary name and mapping
return m_buttonRT;
case "LB": //arbitrary name and mapping
return m_buttonLB;
case "RB": //arbitrary name and mapping
return m_buttonRB;
}
return false;
#else
return Input.GetButton(inputName);
#endif
}
None of the OuyaInputManager.GetButton* variants are working for me.
The only thing that fires is:
Input.GetButtonDown("Fire1")
...and that fires on a double-tap of the trackpad. That at least demonstrates that the controller is paired to the console, and *something* is getting through. I've also put Debug.Logs through my code so I know my Update() is getting called, etc. It's just that these input events aren't triggering.
I've tried "LT", "O", U", and a couple of others... no response.
...none of the if() statements ever fire. I'm trying two variants, one wrapped in #if UNITY_ANDROID, one not wrapped (in case that was a problem). Neither work. The only code that works reliably is in another file:
...here I'm trying a third option (mixing Input.* and OuyaInputManager.* without worrying about platform for now). This if() statement returns true when I double tap the trackpad, and it's the Input.GetButtonDown("Fire1") that's triggering (confirmed by removing others).
I really appreciate the help, I'm sorry I can't get it to work...
...and I see the same behavior as in my game (i.e., the if() never returns true).
I also left Show Controller running for about ten minutes, and it got very laggy. Button highlights took 10-20 seconds to show up. I checked logcat and it was spamming:
InputDispatcher - Dropped event because it is stale. InputDispatcher - Dropped event because it is stale. InputDispatcher - Dropped event because it is stale.
...not sure what that means, but it wasn't doing it for the first couple of minutes.
The question is - which is more efficient, and which gives more control? We have had full success with our controller using the default setup, but the controller feels inexact and a little wonky. Oftentimes the character will move on his own without our input! Naturally we also want to minimise processor load...
I'd stick with my previous answer. If you want to plan for the future and plan to use profiles, you should expect the input to come from Java. As the elites have said, once you optimize the input events you can run at 60 FPS even with input coming from Java.
Stick with the controller example that works for now. There's another video tutorial and a cool example coming.
Comments
Everything went pretty smoothly, except I have no input - I'm not getting any events. Which makes sense as I haven't done anything to set it up!
What I want to do is get get the Unity controller talking to my existing input code as simply as possible. I'm getting a little confused with the various wrappers/managers, so I'm not sure what is the minimal set of changes I can make to get things working.
My primary goal is evaluating perf on Ouya, so I'm trying not to get to caught up in re-writing my input stuff right now (I don't mind doing it later if necessary).
tl;dr: What's the easiest way to simply pipe the Ouya controller though to my existing input code?
EDIT: I realize that's what you're trying to tell me in your previous post... I'm just not 100% clear on how to apply what you've written there! I'm pretty dumb =]
(In an Awake event)
Initialize the SDK: Register the button listener:
OuyaSDK.registerInputButtonListener(new OuyaSDK.InputButtonListener() { onSuccess = (OuyaSDK.InputButtonEvent inputEvent) => { OuyaInputManager.HandleButtonEvent(inputEvent); }, onFailure = (int errorCode, string errorMessage) => { } });Register the axis listener:OuyaSDK.registerInputAxisListener(new OuyaSDK.InputAxisListener() { onSuccess = (OuyaSDK.InputAxisEvent inputEvent) => { OuyaInputManager.HandleAxisEvent(inputEvent); }, onFailure = (int errorCode, string errorMessage) => { } });And then you can access OuyaInputManager with the same API that you previously used with native Unity input.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].
...on this line:
I get basically the same errors for the AxisListener too.
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].
Let me double check I'm using the latest package... I'm 99% sure, but my version of OuyaShowController.cs looks like this:
OuyaSDK.registerInputButtonListener(new OuyaSDK.InputButtonListener<OuyaSDK.InputButtonEvent>()
...as opposed to:
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].
If I use the:
new OuyaSDK.InputButtonListener<OuyaSDK.InputButtonEvent>()
...version I can get it to compile, but my controls don't work =]
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].
Not sure I understand... I'm saying that the version of OuyaShowController.cs that works in the same app calls new differently (i.e., it includes a <type> that your example above doesn't).
Not sure how that relates to the class name?
using System; using System.Collections.Generic; using UnityEngine; public class OuyaControllerExample2 : MonoBehaviour { /// /// This is your assigned developer id /// private const string DEVELOPER_ID = "310a8f51-4d6e-4ae5-bda0-b93878e5f5d0"; void Awake() { try { OuyaSDK.initialize(DEVELOPER_ID); OuyaSDK.registerInputButtonListener(new OuyaSDK.InputButtonListener() { onSuccess = (OuyaSDK.InputButtonEvent inputEvent) => { OuyaInputManager.HandleButtonEvent(inputEvent); }, onFailure = (int errorCode, string errorMessage) => { } }); OuyaSDK.registerInputAxisListener(new OuyaSDK.InputAxisListener() { onSuccess = (OuyaSDK.InputAxisEvent inputEvent) => { OuyaInputManager.HandleAxisEvent(inputEvent); }, onFailure = (int errorCode, string errorMessage) => { } }); } catch (System.Exception ex) { Debug.LogError(string.Format("Awake exception={0}", ex)); } } }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].
However, I just literally pasted in your example code and I'm getting the same compile error:
Assets/Global/Script/Vehicle.cs(80,61): error CS0426: The nested type `InputButtonListener' does not exist in the type `OuyaSDK'
I've also tried re-importing the package, closing and re-opening my project and scenes, etc.
I'll keep poking around :-/
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].
So looking in my OuyaSDK.cs, the only declaration of the InputButtonListener type is this:
public class InputButtonListener<T> : GenericListener<T>
{
}
...which makes sense of the error I'm seeing. The <T> means its expecting a type, right? So I don't understand how this can work:
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].
Now, in my Update() I have stuff like:
if(Input.GetButtonDown("Fire2")) {
thrusting = true;
}
if(Input.GetButtonUp("Fire2")) {
thrusting = false;
}
...but these events don't trigger. What do I need to change? The "Input" part or the "Fire2" part?
EDIT: Amusingly, the only thing I can get to trigger my existing code is a double tap on the track pad... no idea why that would be the case. That is sending a "Fire1" message.
/// /// Wrap Unity's method /// /// /// public static float GetAxis(string inputName) { #if UNITY_ANDROID switch (inputName) { case "LT": return m_axisLeftTrigger; case "RT": return m_axisRightTrigger; case "RX": return m_axisRightStickX; case "RY": return -m_axisRightStickY; case "LX": return m_axisLeftStickX; case "LY": return m_axisLeftStickY; } return 0f; #else return Input.GetAxis(inputName); #endif }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].
/// /// Wrap Unity's method /// /// /// public static bool GetButton(string inputName) { #if UNITY_ANDROID switch (inputName) { case "SYS": //arbitrary name and mapping return m_buttonSystem; case "DPC": //arbitrary name and mapping return m_buttonDPadCenter; case "DPD": //arbitrary name and mapping return m_buttonDPadDown; case "DPL": //arbitrary name and mapping return m_buttonDPadLeft; case "DPR": //arbitrary name and mapping return m_buttonDPadRight; case "DPU": //arbitrary name and mapping return m_buttonDPadUp; case "O": //arbitrary name and mapping return m_buttonO; case "U": //arbitrary name and mapping return m_buttonU; case "Y": //arbitrary name and mapping return m_buttonY; case "A": //arbitrary name and mapping return m_buttonA; case "LT": //arbitrary name and mapping return m_buttonLT; case "RT": //arbitrary name and mapping return m_buttonRT; case "LB": //arbitrary name and mapping return m_buttonLB; case "RB": //arbitrary name and mapping return m_buttonRB; } return false; #else return Input.GetButton(inputName); #endif }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].
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].
None of the OuyaInputManager.GetButton* variants are working for me.
The only thing that fires is:
Input.GetButtonDown("Fire1")
...and that fires on a double-tap of the trackpad. That at least demonstrates that the controller is paired to the console, and *something* is getting through. I've also put Debug.Logs through my code so I know my Update() is getting called, etc. It's just that these input events aren't triggering.
I've tried "LT", "O", U", and a couple of others... no response.
...none of the if() statements ever fire. I'm trying two variants, one wrapped in #if UNITY_ANDROID, one not wrapped (in case that was a problem). Neither work. The only code that works reliably is in another file:
...here I'm trying a third option (mixing Input.* and OuyaInputManager.* without worrying about platform for now). This if() statement returns true when I double tap the trackpad, and it's the Input.GetButtonDown("Fire1") that's triggering (confirmed by removing others).
I really appreciate the help, I'm sorry I can't get it to work...
Input.GetButtonDown("Fire1") is now triggering on a single tap of the trackpad. Not sure if I was wrong before or the behavior changed.
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].
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].
OK, I have monitor running and I've switched back to my game after verifying that the "Show Controller" test app works correctly.
All I get is GC spam, which I assume isn't relevant to this input problem. I don't see any log output when I press buttons.
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].
...and I see the same behavior as in my game (i.e., the if() never returns true).
I also left Show Controller running for about ten minutes, and it got very laggy. Button highlights took 10-20 seconds to show up. I checked logcat and it was spamming:
...not sure what that means, but it wasn't doing it for the first couple of minutes.
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].