Import Unity project in Android, interface Click event loses focus issue

Source: Internet
Author: User

Package Com.t.t;\n\rimport Com.unity3d.player.*;\n\rimport Android.app.nativeactivity;\n\rimport Android.content.res.configuration;import Android.graphics.pixelformat;\n\rimport Android.os.Bundle;import Android.view.keyevent;import Android.view.motionevent;import Android.view.window;import Android.view.windowmanager;public class Unityplayernativeactivity extends nativeactivity{protected UnityPlayer munityplayer;//don ' t change the name of this variable; Referenced from native code//Setup activity [email protected] protected void onCreate (Bundle savedinstancestate) {R Equestwindowfeature (Window.feature_no_title); super.oncreate (savedinstancestate); GetWindow (). Takesurface (NULL); SetTheme (Android. R.style.theme_notitlebar_fullscreen); GetWindow (). SetFormat (pixelformat.rgb_565); munityplayer = new UnityPlayer ( This), if (Munityplayer.getsettings (). Getboolean ("Hide_status_bar", True)) GetWindow (). SetFlags ( WindowManager.LayoutParams.FLAG_FULLSCREEN, Windowmanager.layouTparams.flag_fullscreen); Setcontentview (Munityplayer); Munityplayer.requestfocus ();} Quit [email protected] protected void OnDestroy () {munityplayer.quit (); Super.ondestroy ();} Pause [email protected] protected void OnPause () {super.onpause (); Munityplayer.pause ();} Resume [email protected] protected void Onresume () {super.onresume (); Munityplayer.resume ();} This ensures the layout would be is [email protected] public void onconfigurationchanged (Configuration newconfig) {sup Er.onconfigurationchanged (Newconfig); munityplayer.configurationchanged (newconfig);} Notify Unity of the focus [email protected] public void onwindowfocuschanged (Boolean hasfocus) { Super.onwindowfocuschanged (Hasfocus); munityplayer.windowfocuschanged (Hasfocus);} For some reason the multiple keyevent type are not supported by the NDK.//force event injection by overriding Dispatchk Eyevent () [email protected] public boolean dispatchkeyevent (KeyEvent event) {if (event.getaction () = = Keyevent.acTion_multiple) return munityplayer.injectevent (event); return Super.dispatchkeyevent (event);}  Pass any events not handled by (unfocused) views straight to [email protected] public boolean onKeyUp (int keycode, KeyEvent event) {return munityplayer.injectevent (event); \n\r} @Override public boolean onKeyDown (int keycode, Keyeve          NT Event) {return munityplayer.injectevent (event); \n\r} @Override public boolean ontouchevent (Motionevent event) {return munityplayer.injectevent (event);} /*api12*/public boolean ongenericmotionevent (Motionevent event) {return munityplayer.injectevent (event);}}

Import Unity project in Android, interface Click event loses focus problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.