将Unity与Eclipse集成:返回按钮单击 [英] Integrating Unity with Eclipse: Back Button Click

查看:182
本文介绍了将Unity与Eclipse集成:返回按钮单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主要的活动使用按钮,然后我启动团结活动,但我需要完成它并返回上一个活动,而是整个应用程序关闭。

I have a main activity using a button then i launch the unity activity, but i need to finish it and go back to the previous activity, but instead the whole app is closed.

我该怎么办?
谢谢!

What can I do? Thank you!

编辑:

我使用AR来自高通增强现实(Unity Extension)的玩家
我只有一个主要的活动,我从高通增强现实启动AR播放器。

I use the AR player from Qualcomm Augmented Reality (Unity Extension) I have only one main activity which I start the AR player from Qualcomm Augmented Reality.

主要活动

public class Main extends Activity{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}

public void onBtnStartClick(final View v) {
    Intent i= new Intent(this,ArPart.class);
    startActivity(i);
}

}

public class ArPart extends QCARPlayerActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK)) {
         finish();
    }
    return super.onKeyDown(keyCode, event);
}

}

推荐答案

我发现使用覆盖的 onBackPressed()最简单,但是您还需要在Unity项目中进行更改:

I found it easiest to use the overridden onBackPressed() but to do that you also have to make a change in your Unity project:

void Update ()
{
    if (Input.GetKeyUp (KeyCode.Escape)) {

        AndroidJavaClass jc = new AndroidJavaClass ("com.unity3d.player.UnityPlayer"); 
        AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject> ("currentActivity"); 
        jo.Call ("onBackPressed");
    }
}

然后,在你的活动类中:

Then, in your activity class:

@Override
public void onBackPressed() {

    // Handle the activity however you want,
    // what you do here will be executed when the back button is pressed
}



<另外,请记住,为了正常工作,UnityPlayer对象无法暂停 - 您应该在处理后退按钮事件后暂停。

Also, remember that for this to work as expected, the UnityPlayer object cannot be paused - you should pause it after you've handled the back button press event.

从这个线程获得@Frank Nguyen的信用:无法将Unity中的事件传回到android库jar

Credit goes to @Frank Nguyen from this thread: Can't pass back event from Unity to android library jar.

这篇关于将Unity与Eclipse集成:返回按钮单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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