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项目中,这与node.js / webpack不太搭配。
有没有解决的办法?我的主要目标是提示firebase登录并从中获取身份验证令牌。
您必须通过C#或通过js函数的AJAX调用向Node.JS服务器发送HTTP请求。
您不能直接调用Node.js函数,因为Node本身是一个单独的服务器 - 不同于托管您的游戏/体验的服务器。