英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论