[英]Native Android Activity and with touchevents in Java required using Unity3D
I am using Unity and exporting the Unity Project as an eclipse project 我正在使用Unity并将Unity项目导出为日食项目
this results in a simple NativeApplication 这导致了一个简单的NativeApplication
public class UnityPlayerNativeActivity extends NativeActivity
{
protected UnityPlayer mUnityPlayer;
protected void onCreate (Bundle savedInstanceState)
{
requestWindowFeature(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);
int glesMode = mUnityPlayer.getSettings().getInt("gles_mode", 1);
boolean trueColor8888 = false;
mUnityPlayer.init(glesMode, trueColor8888);
Button b = new Button(this);
b.setOnClickListener( new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Hello From Java", ).show(); } });
RelativeLayout layout = (RelativeLayout) View.inflate(this, R.layout.layout, null);
layout.setLayoutParams(new LayoutParams(300,30));
layout.addView(b);
mUnityPlayer.addView(layout);
View playerView = mUnityPlayer.getView();
setContentView(playerView);
As you can see I have added a relativeLayout that I am inflating on top of the unity layout. 如您所见,我在unity布局的顶部添加了一个我要膨胀的relativeLayout。
However since Unity resides in Native Code and the class is a NativeActivity The touch events for my button will not work in Java - Since Unity compiles to a DLL I do not have access to the native code to send (through JNI) touch events back to Java 但是,因为Unity驻留在本机代码中,并且该类是NativeActivity,所以我的按钮的触摸事件在Java中不起作用-由于Unity编译为DLL,所以我无权访问本机代码以将触摸事件(通过JNI)发送回Java的
Is there another way to do this? 还有另一种方法吗? How can I get touch events to be fired in Java? 如何获取要在Java中触发的触摸事件? Or how can I write an extension of the Native Activity that can capture the touch events in the NDK so I can pass them up to java? 或者,如何编写本机活动的扩展以捕获NDK中的触摸事件,以便将它们传递给Java?
What I find interesting is that If I do not use the unity view, and just setcontentview to my own layout - the touch events do work on java side but the second I use the unity view I no longer can use the touch events in java 我发现有趣的是,如果我不使用统一视图,而只是将contentview设置为自己的布局-触摸事件确实可以在Java端工作,但是第二个我使用统一视图,因此我不再可以在Java中使用触摸事件
What I had works fine the issue is that android requires a meta-data to be added to the xml manifest to tell unity to pass events to dalvik 我所做的很好,问题是android需要将元数据添加到xml清单中,以告诉unity将事件传递给dalvik
see UnityPlayerNativeActivity http://docs.unity3d.com/Documentation/Manual/PluginsForAndroid.html 参见UnityPlayerNativeActivity http://docs.unity3d.com/Documentation/Manual/PluginsForAndroid.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.