Any unity3D experts here?

Pleng

Custom Title
OP
Member
Joined
Sep 14, 2011
Messages
2,439
Trophies
2
XP
2,810
Country
Thailand
Well I've tried both unityanswers and stackoverflow. I can't find anything in the official documentation so I guess I'll try the good old folk at gbaTemp... you never know!

Does anybody know I consume key/touch events in Android, without passing them on to the player. I have exported my game to a "Google Android Project" and I have tried both overriding the dispatchKeyEvent() and onGenericMotionEvent, like this:

Code:
       // For some reason the multiple keyevent type is not supported by the ndk.
        // Force event injection by overriding dispatchKeyEvent().
        @Override public boolean dispatchKeyEvent(KeyEvent event)
        {
            Log.d(String.valueOf(event.getDeviceId()), "Control");
            Toast.makeText(this, String.valueOf(event.getDeviceId()), Toast.LENGTH_SHORT).show();
        
            if (event.getAction() == KeyEvent.ACTION_MULTIPLE)
                return mUnityPlayer.injectEvent(event);
            return super.dispatchKeyEvent(event);
        }
    
        @Override
        public boolean onGenericMotionEvent(MotionEvent event) 
        { 
            Log.d(String.valueOf(event.getDeviceId()), "Control");
            Toast.makeText(this, String.valueOf(event.getDeviceId()), Toast.LENGTH_SHORT).show();
            return true;
        }

I have also tried to attach KeyListener handlers directly to the UnityPlayer object, like this:

Code:
           mUnityPlayer = new UnityPlayer(this);
            mUnityPlayer.setOnKeyListener(new View.OnKeyListener()
            {
                
                @Override
                public boolean onKey(View v, int keyCode, KeyEvent event)
                {
                    Log.d(String.valueOf(event.getDeviceId()), "Control");
                    Toast.makeText(UnityPlayerNativeActivity.this, String.valueOf(event.getDeviceId()), Toast.LENGTH_SHORT).show();
                    return true;
                }
            }
            );

But in both cases, the Java code is not triggering. Any ideas why??
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
  • Sicklyboy @ Sicklyboy:
    maaaaan that's so awesome but I also don't want to fork over a hundo for it
  • Veho @ Veho:
    The fuuuuu---
  • Veho @ Veho:
    I thought it was an actual xBox at that price.
  • Sicklyboy @ Sicklyboy:
    I wanna grab a 360 Slim and a 360 E one of these days. Missed the boat of getting them at their lowest though, once they were discontinued. Could've got them for cheap back when I was a broke 20 something working at Target, but then again, I was a broke 20 something working at Target
  • Veho @ Veho:
    Being broke is no fun.
  • K3Nv2 @ K3Nv2:
    @Sicklyboy, $150 isn't that bad for a jtag slim on ebay
  • Veho @ Veho:
    I only wish it was actually playable.
  • Veho @ Veho:
    There's a guy on the Tube of You that makes playable mechanical arcade games out of Lego. This could work on the same principle.
  • Veho @ Veho:
    Just a couple of guys taking their manatee out for some fresh air, why you have to molest them?
  • Veho @ Veho:
    Stupid Chinese shop switched their shipping company and this one is slooooooow.
  • LeoTCK @ LeoTCK:
    STOP BUYING CHINESE CRAP THEN
  • LeoTCK @ LeoTCK:
    SUPPORT LOCAL PRODUCTS, MAKE REVOLUTION
  • LeoTCK @ LeoTCK:
    THEY KEEP REMOVING LOCAL SHIt AND REPLACING WItH INFERIOR CHINESE CRAP
  • LeoTCK @ LeoTCK:
    THATS WHY MY PARTNER CANT GET A GOOTWEAR HIS SIZE ANYMORE
  • LeoTCK @ LeoTCK:
    HE HAS BIG FOOT AND BIG DUCK
  • LeoTCK @ LeoTCK:
    d*ck i mean*
  • LeoTCK @ LeoTCK:
    lol
  • Veho @ Veho:
    Mkay.
  • Veho @ Veho:
    I just ordered another package from China just to spite you.
  • SylverReZ @ SylverReZ:
    Leo could not withstand communism.
  • SylverReZ @ SylverReZ:
    Its OUR products to begin with lol.
    SylverReZ @ SylverReZ: Its OUR products to begin with lol.