2016-04-19 49 views
0

我正在开发一个与Unity3d集成的应用程序,在我的代码的某个部分中,我调用了启动Unity3d代码的UnityPlayerActivity。当用户完成使用Unity3d时,他按下一个按钮并返回到Android代码。 我的问题是,当我回去的Android代码,UnityPlayerActivity调用后:如何让Android应用程序继续运行并退出Unity Activity

@Override protected void onDestroy() 
{ 
    mUnityPlayer.quit(); 
    super.onDestroy(); 
} 

的应用程序被关闭,不仅统一活动。我不能称这种方法,但我认为这会浪费记忆。

有没有什么办法可以只退出Unity3d活动并让我的应用程序正常运行,以便我可以再次启动Unity3d部件?

Tks

+0

您可以在新线程中开始统一活动,然后在完成工作后杀死该线程 –

+0

我不明白你的意思问题。请详细说明你想从你的unity3d游戏返回到android Activity吗? – Lampard

+0

Lipian,它是一个内置小型Unity游戏的android项目,我想玩那个游戏并回到我的android项目。 – user2494863

回答

0

你也可以只使用反射,因此避免调用杀()方法(这就是所谓的退出()),它可以杀死当前进程

try { 
     //1 
     Field v = unityPlayer.getClass().getDeclaredField("v"); 
     v.setAccessible(true); 
     Method a = v.getType().getMethod("a"); 
     a.invoke(v.get(unityPlayer)); 

     //2 
     Field o = unityPlayer.getClass().getDeclaredField("o"); 
     o.setAccessible(true); 
     o.set(unityPlayer, true); 

     //3 
     unityPlayer.pause(); 
     Method unloadVR = unityPlayer.getClass().getDeclaredMethod("unloadGoogleVR"); 
     unloadVR.setAccessible(true); 
     unloadVR.invoke(unityPlayer); 

     //4 
     unityPlayer.removeAllViews(); 

     //5 
     Method h = unityPlayer.getClass().getDeclaredMethod("h"); 
     h.setAccessible(true); 
     h.invoke(unityPlayer); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
相关问题