Search Unity

Gamepad Support

Discussion in 'Android' started by descenderdante, May 6, 2013.

  1. descenderdante

    descenderdante

    Joined:
    Sep 3, 2009
    Posts:
    218
    I have been looking into Gampad support (HID gamepads specifically) and have been having trouble with getting all the events to fire with Unity.

    On the Java layer I’d expect the following functions to fire on the base activity.
    -onKeyDown
    -onKeyUp
    -onGenericMotionEvent

    This works great in a native android app however when I tweak our root activities to be something even as simple as and launch an app theonGenericMotionEvent function is never called. However if I leave the app and come back it then will fire as expected.

    Code (csharp):
    1.  
    2.        @Override
    3.         public boolean onGenericMotionEvent(MotionEvent event) {
    4.               FLAPLog.err(FLAPUnityActivity.class, "OnGenericMotion:");
    5.                return true;
    6.               // TODO Auto-generated method stub
    7.               //return super.onGenericMotionEvent(event);
    8.        }
    9.  
    I cannot find a cause for this to work after resuming the app but not on a fresh launch was hoping anyone here would.
     
  2. vontio

    vontio

    Joined:
    Jul 14, 2012
    Posts:
    4
    same problem,onGenericMotionEvent never called.
     
  3. pavan7544

    pavan7544

    Joined:
    Jul 6, 2012
    Posts:
    2
    By calling below two methods in your view initialization resolve the issue.
    setFocusable(true);
    setFocusableInTouchMode(true);
     
  4. pavan7544

    pavan7544

    Joined:
    Jul 6, 2012
    Posts:
    2
    Call these methods while initializing your view :
    setFocusable(true);
    setFocusableInTouchMode(true);