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.
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;
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(); }
internal void HandleButtonEvent(OuyaSDK.OuyaPlayer p, OuyaSDK.KeyEnum b, OuyaSDK.InputAction bs) { // ToDo Implement any button event actions – not needed in this }
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; }
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.
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
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
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.
Comments
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].
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;
}
CLARK
by GoldenTricycle
Developer for CLARK / GoldenTricycle
Developer of OuyaInput Framework >> GIT
CLARK
by GoldenTricycle
Developer for CLARK / GoldenTricycle
Developer of OuyaInput Framework >> GIT
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].
CLARK
by GoldenTricycle
Developer for CLARK / GoldenTricycle
Developer of OuyaInput Framework >> GIT
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].