Advertisement
Guest User

OuyaNguiCustomInput

a guest
Jul 11th, 2013
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma strict
  2.  
  3. private var deadZone : float = 0.25;
  4. private var axisValue : float;
  5. private var acceptInput : boolean = true;
  6.  
  7. function Start()
  8. {
  9.     if(OuyaSDK.IsOUYA())
  10.     {
  11.         UICamera.current.onCustomInput = OuyaNguiInput;
  12.     }
  13. }
  14.  
  15. function OuyaNguiInput()
  16. {
  17.     if(SuperInputMapper.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_DPAD_RIGHT, OuyaSDK.OuyaPlayer.player1)) UICamera.Notify(UICamera.selectedObject, "OnKey", KeyCode.RightArrow);
  18.     if(SuperInputMapper.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_DPAD_UP, OuyaSDK.OuyaPlayer.player1)) UICamera.Notify(UICamera.selectedObject, "OnKey", KeyCode.UpArrow);
  19.     if(SuperInputMapper.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_DPAD_LEFT, OuyaSDK.OuyaPlayer.player1)) UICamera.Notify(UICamera.selectedObject, "OnKey", KeyCode.LeftArrow);
  20.     if(SuperInputMapper.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_DPAD_DOWN, OuyaSDK.OuyaPlayer.player1)) UICamera.Notify(UICamera.selectedObject, "OnKey", KeyCode.DownArrow);
  21.    
  22.     axisValue = SuperInputMapper.GetAxis (OuyaSDK.KeyEnum.AXIS_LSTICK_Y, OuyaSDK.OuyaPlayer.player1);
  23.     if(axisValue > deadZone)
  24.     {
  25.         if(acceptInput)
  26.         {
  27.             UICamera.Notify(UICamera.selectedObject, "OnKey", KeyCode.DownArrow);
  28.             acceptInput = false; // prevents auto-fire
  29.         }
  30.     }
  31.     else if(axisValue < -deadZone)
  32.     {
  33.         if(acceptInput)
  34.         {
  35.             UICamera.Notify(UICamera.selectedObject, "OnKey", KeyCode.UpArrow);
  36.             acceptInput = false; // prevents auto-fire
  37.         }
  38.     }
  39.     else
  40.     {
  41.         // no joystick movement or between deadZone (= little to no movement at all)
  42.         acceptInput = true; // enable joystick input again
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement