在Unity项目和Android Studio Java代码之间共享数据。

huangapple go评论91阅读模式
英文:

Share data between Unity Project to Android Studio java code

问题

我按照以下步骤将我的Unity项目导出到Android Studio:

https://forum.unity.com/threads/integration-unity-as-a-library-in-native-android-app.685240/

但我想问一下,是否有任何选项可以从我的本机Android应用程序Intent发送数据到Unity脚本,因为我正在制作一款在线游戏,我需要将我的令牌传输到Unity中。

我已经使用**Encrypted SharedPreference**库将令牌保存在Android Studio中的共享首选项中,服务器需要令牌以响应请求,因此我希望从我的Android Intent获取令牌并传递给Unity脚本。

或者在Unity中是否有任何方法可以解密此令牌。

请帮帮我,我被卡住了。

英文:

I Export my unity project to the android studio using these steps:

https://forum.unity.com/threads/integration-unity-as-a-library-in-native-android-app.685240/

But I want to ask that is there any option that I can send data from my native android app Intent to unity scripts because I am making an online game and I need to transfer my tokens to unity.

I have saved the token in shared preferences using Encrypted SharedPreference library in the android studio, server required token to respond on request so I want the token from my android intent to unity script.

Or Is there any way in unity to decrypt this token.

Please help me I am stuck

答案1

得分: 4

我的解决方法将是将这个问题视为在Unity中使用Android插件的情况。

因此,您可以使用任何继承自UnityPlayerActivity的活动,或者创建您自己的活动。

然后使用内置的方法UnityPlayer.UnitySendMessage,将游戏对象名称作为参数传递,该名称将附加到接收器脚本,接收器脚本内的接收器方法的名称,以及您想要处理的数据,对于您的情况是令牌。
类似于:UnityPlayer.UnitySendMessage(gameObjectName, "OnResultMethodName", tokenString);

您可以在这里找到如何执行此操作的示例:https://github.com/Unity-Technologies/uaal-example

英文:

My workaround will be to approach this problem as if you are using an android plugin for Unity.

So you can use any activity that inherits from UnityPlayerActivity, or create your own.

Then use the in-build method UnityPlayer.UnitySendMessage, passing as parameters the gameObjectName that will have the receiver script attached, the name of the receiver method inside the receiver script, and the data you want to handle, in your case, the token.
something like: UnityPlayer.UnitySendMessage(gameObjectName, "OnResultMethodName", tokenString);

You can see an example of how to do that here: https://github.com/Unity-Technologies/uaal-example

huangapple
  • 本文由 发表于 2020年5月19日 21:30:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/61892304.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定