8

Hello I am currently writing an Android app that uses Unity to display a 3D model. The user is capable of interacting with the model as selecting objects in the scene. What I am having trouble is passing data back to the Android activity.

I currently have the Unity scene executing as a subview, can anyone point me in the direction on how to pass data from the scene to Android?

Do I have to create a Java plugin, explained here? link text

If this is the case, does anyone have any tutorials on this? The original material is kind of lacking. Thanks in advance.

Lex Li
  • 60,503
  • 9
  • 116
  • 147
user1561427
  • 81
  • 1
  • 2
  • I found the answer to my question in this thread: [enter link description here][1] [1]: http://stackoverflow.com/questions/7749841/unity3d-integration-with-android – user1561427 Jul 30 '12 at 15:59
  • The unity tag is for Microsoft Unity. Please don't misuse it. – Lex Li Aug 03 '12 at 06:14
  • Hi Lex Li I have faced same problem. I am trying to pass some value from Android activity and display it in unity view. So is it possible for you share your source code or some valuable ideas. Thanks in advance. – atrivedi Aug 29 '12 at 06:13

2 Answers2

1

If you want to communicate from Unity to an Activity (Java code) you need to create a native plugin. Then in C# from Unity you can find the activity or the JavaObject and pass it parameters.

Check this out.

https://www.thepolyglotdeveloper.com/2014/06/creating-an-android-java-plugin-for-unity3d/

After you watch this page the summary would be:

  • Create a simple Unity Project.
  • Create an Android native plugin. Can be an activity or a simple class.
  • Export the .jar or .aar from Android Studio (i recommend the .aar since it's the android studio library. There you can manage the AndroidManifest.xml and then Unity will merge it with the final one)
  • Put the .aar into Unity project under Assets/Plugins/Android folder.
  • Create a c# script calling for your class method.
  • Build the .apk from Unity (Remember adding the company, product name and bundle id)
  • Run the apk in a device.
  • Test
-2

I'm not sure since I haven't worked with Unity before. But there are some ways to transfer data between activities, I hope it'll help you.

  • Thank you for the comment I understand how to pass data between activities. What I am unsure of his how to pass data from Unity Scene back to an Activity. – user1561427 Jul 29 '12 at 23:11