How to communicate between Android and Unity?

I can understand how to embed a unity project in an Android project from articles on the Internet and into the Unity Education section of http://unity3d.com/learn . I'm having communication problems between Unity and Android. I need to send Unity some JSON data that will contain numbers and values ​​to display and URLs for multiple images. From there, inside the unity scene, I want to do some animation. Based on the choices made by the user, I need to send the appropriate requests to our server and open various actions.

In normal Android development, I transferred information from one activity to another using the Bundle, but I cannot figure out how to do the same with Unity and Android. Getting custom selections from the Unity scene in my application is also a problem that needs to be resolved.

+5
source share
1 answer

Unity is not a regular Android application. This is more like a library integrated into an Android app.

Unity docs demonstrate that to call methods on the Android side of Unity, you can use AndroidJavaClass (for references to Java classes and static calls) and AndroidJavaObject (for references to objects).

To interact differently, you can use UnitySendMessage () in Java. The last parameter in UnitySendMessage () is an optional string argument that you can use to pass JSON to Unity.

In Unity, you can use JsonUtility.FromJson for deserialization or some third-party scripts for json parsing, there is a lot on github.

+2
source

Source: https://habr.com/ru/post/1247521/


All Articles