When the Unity view was embedded in Android view, there was an issue where Android view was unable to focus, becausenativeactivity was introduced after Android2.3 and does not support devices below that version. Because touch/motion events are handled in native code, Java views typically do not see these events.
So how do we solve these problems?
Method One:
The unified forwarding mechanism allows events to be propagated to DALVIKVM, and thefollowing two lines of code are added under the Activity sub-node in the Androidmanifest.xml file:
<meta-data android:name= "Android.app.lib_name" android:value= "Unity"/>
This will create a problem, first look at:
Such an interface, I want to double-click the screen can show and hide the above titlebar, the middle of the button-type u3d inside.
Implement listening double-click screen, I am in the activity of ontouchevent (Motionevent Event) This method listens for events and then processes them, but if not configured in the activity's configuration file <meta-data Android:name= "Unityplayer. Forwardnativeeventstodalvik "android:value=" true "/>", that is, the method above, then Ontouchevent (Motionevent Event) This method will not execute, if the configuration of the , then you can not click on the Unity3d inside the button, that is, the middle of the two. In other words, u3d and Android can not be double click events?
So I used one of the following methods:
Method Two
Overlay a view on the u3d view, such as Relativelayout, and then do not control the distribution mechanism on the child nodes of the activity, which means that u3d click events or their own processing, will not be distributed to Java Dalvik, and then, Click on the event, such as I want to listen to double-click event, then how to do? By the coverage of the view to achieve, to the view to add ontouchevent monitoring, so as to determine whether the Click event occurred, about the Click event How to judge, please refer to my other blog.
Android to judge double-click event (refer to Android source, determine time interval and range)
In this case, the problem with U3d and Android has been dealt with and seems to be perfect, but there is still a problem:
For the added view, after setting the ontouchevent, but only can hear the action_down,action_up and other events are not listening. According to the mechanism of event distribution, after view has processed the Action_down event, it should be passed into u3d, that is, U3d's native method handles the Click event, and after processing it, it may not be passed back to Java Dalvik, and then this phenomenon is caused? Now it's just my guess that the real reason needs to be further validated.
Method Three
In fact, we do all of the above is Shejinqiuyuan, because in u3d, completely can call the Android method, so the following idea is, u3d to get the click event, and then if you need Android to do what processing, then Android gives the appropriate method, let u3d to make the call, Then there will be no conflict on the click event.
As for the treatment of this method, I will specifically write an article blog. But to be sure, this is the right approach.
Unity3d and Android event conflict resolution