通过Unity3D在node.js中调用javascript函数?

时间:2017-12-19 07:00:14

标签: javascript node.js unity3d

Unity WebGL有一个从jslib调用javascript函数的方法,但是我需要将这些函数调用集成到node.js以便使用firebase。

我尝试做的事情如下:

// entry.js:
require("./style.css");
document.write(require("./content.js"));

require('./UnityLoader.js');

var firebase = require('firebase');

function foo() {
    window.alert("ENTRY HELLOW WORLD");
}


wvar gameInstance = UnityLoader.instantiate("gameContainer", "Build/WebGLNodeContainer.json");
document.write('<div id="gameContainer" style="width: 960px; height: 600px; margin: auto"></div>');

然后从Unity内部我尝试进行外部调用:

public class FirebaseWebGL : IFirebaseLib
    {
        [DllImport("__Internal")]
        private static extern void foo();

        public void Login(string username, string password)
        {
              foo();
        }
    }

我并不感到惊讶,这不起作用,而Unity's docs claim you can call javascript in your webpage他们提供的说明涉及将javascript文件打包到Unity项目中,该项目对节点不起作用。 JS /的WebPack。

有解决方法吗?我的主要目标是提示firebase登录并从中获取身份验证令牌。

1 个答案:

答案 0 :(得分:1)

您必须通过C#或通过js函数的AJAX调用向Node.JS服务器发送HTTP请求。

您无法直接调用Node.js函数,因为Node本身是一个单独的服务器 - 与托管您的游戏/体验的服务器不同。