public static JoystickType GetControllerType(OuyaSDK.OuyaPlayer player) { // check the player to see what joystick type they have OuyaGameObject.Device device = OuyaGameObject.devices.Find(delegate(OuyaGameObject.Device d) { return((null == d) ? false : (d.player == player)); }); if (null == device) { return(JoystickType.none); } return(GetControllerType(device.name)); }
void Start() { string deviceType = GetDeviceType(); PlayerPrefs.SetString("device_type", deviceType); Input.ResetInputAxes(); Application.targetFrameRate = 60; DontDestroyOnLoad(transform.gameObject); #region Init Devices if were not on Android #if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_STANDALONE_LINUX //Get Devices attached to computer: devices = new List<OuyaGameObject.Device>(); int deviceCount = 0; int controllerCounter = 1; foreach (string joystick in Input.GetJoystickNames()) { OuyaGameObject.Device device = new OuyaGameObject.Device(); device.id = deviceCount; device.player = (OuyaSDK.OuyaPlayer)controllerCounter; device.name = joystick; devices.Add(device); deviceCount++; controllerCounter++; } #endif #endregion #region Init OUYA And Handlers try { //First Initalize Ouya SDK; #region Initialize OUYA //Initialize OuyaSDK with your developer ID //Get your developer_id from the ouya developer portal @ http://developer.ouya.tv OuyaSDK.initialize(DEVELOPER_ID, UseLegacyInput); #endregion } catch (System.Exception ex) { Debug.LogError(string.Format("Failed to initialize OuyaSDK exception={0}", ex)); } try { #region Register button listener //Register the for Button Input handling through the static class OuyaSDK.registerInputButtonListener(new OuyaSDK.InputButtonListener<OuyaSDK.InputButtonEvent>() { onSuccess = (OuyaSDK.InputButtonEvent inputEvent) => { //Assign our handler in the static class. OuyaInputManager.HandleButtonEvent(inputEvent); }, onFailure = (int errorCode, string errorMessage) => { // Your app probably wants to do something more sophisticated than popping a Toast. This is // here to tell you that your app needs to handle this case: if your app doesn't display // something, the user won't know of the failure. //Debug.Log(string.Format("Could not fetch input (error {0}: {1})", errorCode, errorMessage)); } }); #endregion } catch (System.Exception ex) { Debug.LogError(string.Format("Failed to register button listener exception={0}", ex)); } try { #region Register axis events //Register the for Axis Input handling through the static class OuyaSDK.registerInputAxisListener(new OuyaSDK.InputAxisListener<OuyaSDK.InputAxisEvent>() { onSuccess = (OuyaSDK.InputAxisEvent inputEvent) => { //Assign our handler in the static class. OuyaInputManager.HandleAxisEvent(inputEvent); }, onFailure = (int errorCode, string errorMessage) => { // Your app probably wants to do something more sophisticated than popping a Toast. This is // here to tell you that your app needs to handle this case: if your app doesn't display // something, the user won't know of the failure. //Debug.Log(string.Format("Could not fetch input (error {0}: {1})", errorCode, errorMessage)); } }); #endregion } catch (System.Exception ex) { Debug.LogError(string.Format("Failed to register axis events exception={0}", ex)); } #endregion }