UnitySendMessage在非社区活动中不起作用 [英] UnitySendMessage not working from non-unity activity

查看:460
本文介绍了UnitySendMessage在非社区活动中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个android插件,该插件应启动另一个活动(使用UI和所有内容...). 该活动(当然不是从UnityPlayerActivity继承的)应该将消息发送到Unity C#代码. 我正在尝试调用UnityPlayer.UnitySendMessage ,我在发送消息之前看到了我的日志,但是 C#端没有得到它(没有引发异常).

I'm developing an android plugin which should start another activity (with UI and everything...). This activity (which is not inherits from UnityPlayerActivity of course) should send message to the Unity C# code. I'm trying to call UnityPlayer.UnitySendMessage, I see my log a moment before sending the message but the C# side doesn't get it (no exception is raised).

这是从其他活动中调用的回调:

@Override
public void generatePayload() {
   try {
      Log.v(TAG, "generatePayload was triggered");
      UnityPlayer.UnitySendMessage("AndroidObject", "generatePayloadMessage", "");
   } catch (Exception ex) {
      Log.e(TAG, "failed to send message to unity");
   }
}

  • 我尝试从统一的主要活动中调用此方法,并且在统一方面已成功接收到消息.
  • 我也尝试过从其他活动中发送消息(如我应该的那样),但是在主线程中也行不通...
  • 有什么建议吗? UnityActivity不在前台时,我不能发送消息给统一吗?如果是这种情况,该怎么办?

    Any suggestions? Can't I send message to unity while UnityActivity isn't in foreground? If this is the situation - what can I do?

    推荐答案

    您的代码中仅在目标对象和方法上方没有发送消息/字符串,您正在发送空字符串以生成generatePayLoadMessage([未发送任何内容])

    there is no message/string sent in your code above only a target object and method, you are sending an empty string to generatePayLoadMessage([nothing being sent])

    尝试

    UnityPlayer.UnitySendMessage("AndroidObject","generatePayloadMessage","Hello world");

    UnityPlayer.UnitySendMessage("AndroidObject", "generatePayloadMessage", "Hello world");

    还请说明您在Unity方面设置的内容,以处理消息.

    also please state what you have set up on the Unity side to handle the message.

    这篇关于UnitySendMessage在非社区活动中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆