简体   繁体   English

在 Unity Project 之间共享数据到 Android Studio java 代码

[英]Share data between Unity Project to Android Studio java code

I Export my unity project to the android studio using these steps:我使用以下步骤将我的统一项目导出到 android 工作室:

https://forum.unity.com/threads/integration-unity-as-a-library-in-native-android-app.685240/ 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.但是我想问一下,是否有任何选项可以将数据从我的本机 android 应用 Intent 发送到统一脚本,因为我正在制作在线游戏,我需要将我的代币转移到统一。

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.我已经使用 android 工作室中的Encrypted SharedPreference库将令牌保存在共享首选项中,服务器需要令牌来响应请求,所以我想要来自我的 android 意图的令牌到统一脚本。

Or Is there any way in unity to decrypt this token.或者有什么方法可以统一解密这个令牌。

Please help me I am stuck请帮帮我我卡住了

My workaround will be to approach this problem as if you are using an android plugin for Unity.我的解决方法是解决这个问题,就像您使用 Unity 的 android 插件一样。

So you can use any activity that inherits from UnityPlayerActivity , or create your own.因此,您可以使用继承自UnityPlayerActivity的任何活动,或创建自己的活动。

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.然后使用内置方法UnityPlayer.UnitySendMessage ,将附加接收器脚本的游戏对象名称作为参数传递,接收器脚本中接收器方法的名称,以及您想要处理的数据,在您的情况下,令牌。 something like: UnityPlayer.UnitySendMessage(gameObjectName, "OnResultMethodName", tokenString);类似于: UnityPlayer.UnitySendMessage(gameObjectName, "OnResultMethodName", tokenString);

You can see an example of how to do that here: https://github.com/Unity-Technologies/uaal-example您可以在此处查看如何执行此操作的示例: https://github.com/Unity-Technologies/uaal-example

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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