Unity3d 与 Android 的集成
我需要创建一个android应用程序,它由在Unity3d(动画等)和AndroidSDK上编写的部分组成(通过androidSDK,我的意思是用java、清单和资源编写的一些活动)
事实上,我已经有了这些部分(至少是模拟)准备好=))我不知道如何在它们之间进行通信。
我读过很多关于unity3d android集成的文章(主要是关于所谓的“插件”的东西),但未能理解这个工作人员是如何工作的=(我理解的主要内容(除了官方参考文献之外的每个人都写过)是关于插件的文档非常差...=)
我能理解的唯一沟通方式是从unity3d脚本(使用AndroidJavaClass和AndroidJavaObject)发出意图(广播),以便我的活动(用java编写)可以处理它。但有些事情告诉我这不是最好的解决方案...
我读到的问题是我需要使用 JNI (这是 java 本机接口 - 为什么?!? - 为什么我需要使用本机代码?)
我需要在java上创建一些中级代码,其目的是与我的java活动进行通信,使用AndroidNDK编译它并作为插件包含到我的Unity3d项目中?我怎样才能写那个中间层呢?我是否需要使用 UnityPlayer 而不是“Activity”作为基类,为什么?
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.
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... =)
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...
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?)
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是有关 在普通 Android 应用程序中运行 Unity。有一个关于 在 Android 视图内运行 Unity。一旦您启动并运行它,您就可以开始轻松地将场景嵌入到您的应用程序中的任何位置。
当您需要从 Unity 调用 Java Android 应用程序时,您可以添加以下代码:
然后您可以通过 Activity AndroidJavaObject 在您的 Activity 上调用您想要的任何方法。像这样的事情:
Here is a tutorial on the basics of running Unity inside of a normal Android app.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.
When you need to call into the Java Android app from Unity, you can add this code:
And then you can call any method you want on your activity through the activity AndroidJavaObject. Something like this:
为了完全支持Android,您不需要在java上创建一些中间层代码。
相反,您应该:
此方法有助于编写推送通知、应用程序计费等......
此处参考#:http ://docs.unity3d.com/Documentation/Manual/PluginsForAndroid.html(->扩展UnityPlayerActivity Java代码)
此外,通过使用下面的代码:
您可以在 Unity 上使用 Android 完成大部分神奇的事情
注意*:yourFunctionName 必须在从 UnityPlayerActivity 扩展的主活动中实现(请参阅步骤 2)
问候,
For fully supporting on Android, you don't need to create some middle-level code on java.
Instead, you should:
This method is helpful for writing Push notification, in app billing, etc…
Ref# here: http://docs.unity3d.com/Documentation/Manual/PluginsForAndroid.html (-> Extending the UnityPlayerActivity Java Code)
And in addition, by using below code:
You can do most of magic things with Android on Unity
Note*: yourFunctionName must be implemented inside your main activity which extend from UnityPlayerActivity (Look at step 2)
Regards,
2020 年的 unity3D 现在根本不需要 android SDK。
你只需点击
文件->建筑设置->切换平台->建造。
然后你就可以创建你的Android应用程序了。
the unity3D in 2020 isn't needed android SDK at all nowadays.
you can just click
file -> building setting -> switch platform -> build.
and you can create your android app.