使用Unity3D所需的原生Android的活动,并在Java中touchevents [英] Native Android Activity and with touchevents in Java required using Unity3D

查看:290
本文介绍了使用Unity3D所需的原生Android的活动,并在Java中touchevents的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用统一和出口统一项目作为一个Eclipse项目

I am using Unity and exporting the Unity Project as an eclipse project

这会导致一个简单的NativeApplication将

this results in a simple 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);

正如你可以看到我已经添加了我的统一布局的俯视一个充气RelativeLayout的。

As you can see I have added a relativeLayout that I am inflating on top of the unity layout.

但是,由于统一驻留在本地code和类是NativeActivity的
触摸事件对我的按钮将不会在Java中的工作 -
由于统一编译成一个DLL我没有访问本地code派(通过JNI)触摸事件回Java

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

有另一种方式来做到这一点?
我怎样才能触摸事件在Java中被解雇?或者我怎么能写的本地活动,可以拍摄在NDK的触摸事件的延伸,所以我可以将它们传递到java吗?

Is there another way to do this? How can I get touch events to be fired in 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?

我觉得有趣的是,如果我不使用的统一视图,只是的setContentView我自己的布局 - 触摸事件做Java方面的工作
但第二次我用的是统一视图我不再可以使用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

推荐答案

我有什么工作正常,问题是,机器人需要的元数据添加到XML清单告诉团结传递事件的Dalvik

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

看UnityPlayerNativeActivity
http://docs.unity3d.com/Documentation/Manual/PluginsForAndroid.html

see UnityPlayerNativeActivity http://docs.unity3d.com/Documentation/Manual/PluginsForAndroid.html

这篇关于使用Unity3D所需的原生Android的活动,并在Java中touchevents的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆