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
    Psionic Roshambo @ Psionic Roshambo: https://www.youtube.com/watch?v=4N-3vv4kzdk