简体   繁体   中英

How to pass data from Unity scene to Android Activity

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.

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 ac# 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM