AirConsole Unity插件 - 在Unity调试器工作时,WebGL构建不起作用

时间:2016-03-22 21:04:26

标签: unity3d airconsole

我们使用AirConsole-plugin创建了Unity3D的小型演示,该演示在Unity调试器中运行。 (如果我按播放,浏览器会打开,有时它会起作用,有时它不会。如果没有,可以重新启动Unity,然后它可以工作。) 如果我们创建发布版本或开发人员版本,它就不再有效。它会正确加载图像,但控制器(虚拟+电话)大部分时间都会“加载”。有时他们会到达第一个正确的HTML页面,但随后他们发送的消息似乎没有到达屏幕一侧。 当我在构建之后单击“打开导出的端口”时,除了一次之外它也不起作用。

我收到一条错误消息: “未捕获的TypeError:无法读取未定义的属性'postQueue'”

此错误消息始终显示: “主要准备前时间:176毫秒UnityLoader.js:1 Module.printErr @ UnityLoader.js:1“

您知道这些错误消息的含义吗?

1 个答案:

答案 0 :(得分:0)

I've tried a lot, but this seems to solve the problem: Be sure to attach the event listeners in the Awake method, as they do in basic example application.

public class AirConsoleService : MonoBehaviour
{
    void Awake()
    {
        // register events
        AirConsole.instance.onReady += OnReady;
        AirConsole.instance.onMessage += OnMessage;
        AirConsole.instance.onConnect += OnConnect;
        AirConsole.instance.onDisconnect += OnDisconnect;
        // etc. ...
    }
    // etc. ...
}

My problem was that my AirConsoleService was static and not a MonoBehaviour to be sure that there is only one instance of AirConsoleService. It works perfectly for the debug 'play' mode, but in the release build, the AirConsole somehow does not know the deviceID which sent the message (this means, we get -1 from method ConvertDeviceIdToPlayerNumber. And this explains why the controllers don't get any signal from the screen.

My solution: I've attached it as a component to the AirConsole object.

Further notes:

  • Anti-Virus may block content.
  • Your PC/server has to be fast.
  • During development, log the deviceID and the playerID and the current active deviceIDs.
  • Often restart Unity or the integrated webserver of the plugin