与Android Unity3d整合 [英] Unity3d integration with android

查看:175
本文介绍了与Android Unity3d整合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要建立一个Android应用程序其中包括部分写在Unity3d(动画等),并就AndroidSDK(由androidSDK我的意思是用Java编写的,体现一些活动和资源)

I need to create an android application which consists of parts written on Unity3d (animation and so on) and on AndroidSDK (by androidSDK I mean few activities written in java, manifest and resources)

其实我已经有那些部分(至少嘲笑准备=))我无法弄清楚如何将它们之间的通信。

In fact I already have those parts (At least mocks are ready=)) And I can't figure out how to communicate between them.

我读了很多关于unity3d的Andr​​oid整合的文章(主要是关于东西叫做插件),并没有理解它是如何工作的人员=(主要的事情我知道(大家exept裁判官写的那个)是关于插件的文档是很可怜的...... =)

I've read a lot of articles about unity3d android integration (mostly about things called "plugins") and failed to understand how this staff works=( The main thing I understood (everyone exept official refs wrote about that) is that documentation about plugins is very poor... =)

沟通,我可以理解,唯一的办法就是让来自unity3d脚本(使用AndroidJavaClass和AndroidJavaObject),所以我的活动(用Java编写的)意向(广播)可以处理它。可是,我告诉我这是不是最好的解决办法...

The only way to communicate which I can understand is to make an intent (broadcast) from unity3d script (using AndroidJavaClass and AndroidJavaObject) so my activity (written in java) can handle it. But something tells me it's not the best solution...

我了解的问题是,我需要使用JNI(这是Java本地接口 - 为什么 - ?!?为什么我需要使用本机code)

What I read about the problem is that I need to use JNI (which is java native interface - WHY?!? - why do I need to use native code?)

我是否需要创建Java的一些中层code的目的是与我的Java活动进行沟通,用AndroidNDK编译它,包括在我的Unity3d项目作为一个插件?我怎么能写中间层不是?我需要使用,而不是活动UnityPlayer作为基类,为什么?

Do I need to create some middle-level code on java which purpose is to communicate with my java activity, compile it using AndroidNDK and include into my Unity3d project as a plugin? How can I write that middle layer than? Do I need to use UnityPlayer instead of "Activity" as a base class and why?

推荐答案

以下是关于<一个基础教程href="http://unity3d.com/support/documentation/Manual/Android-Integrating%20Unity%20With%20Eclipse.html">running团结正常的Andr​​oid应用内。

目前在一个伟大的教程运行统一的Andr​​oid浏览里面的。一旦你得到这个启动和运行,你可以从任何地方开始在你的应用程序很容易地嵌入场景。

There is a great tutorial on running Unity inside of Android Views. Once you get this up and running you can start embedding scenes easily anywhere in your App.

当你需要调用从统一的Java的Andr​​oid应用程序,你可以添加这个code:

When you need to call into the Java Android app from Unity, you can add this code:

AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); 
AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");

然后就可以通过活动AndroidJavaObject致电您的活动,你想要的任何方式。事情是这样的:

And then you can call any method you want on your activity through the activity AndroidJavaObject. Something like this:

activity.Call("yourFunctionName", parameters);

这篇关于与Android Unity3d整合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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