Firebase 存储 SDK 在 Unity Web Build 中不起作用

Firebase Storage SDK not working in Unity Web Build

我正在开发一个使用 Firebase 存储在运行时下载一些资源的项目。

问题是我需要生成我的应用程序的 Web 构建,当我尝试时,Unity 说找不到 Firebase 命名空间。

是否有将 Firebase 存储与 WebGL 构建一起使用的解决方法?我读过有人说 Firebase 的 REST API 是可能的,但我认为这不太容易,因为该项目使用下载进度和 SDK 提供的其他内容。

如果知道一些在 Unity Web 构建中运行良好的其他服务(我可以在外部存储文件并在我的应用程序中下载它们),那就太好了。目前我只知道Firebase,所以我也想知道其他参考资料。

很遗憾,Firebase Unity SDK does not support the web target at this time. Currently the way it binds through C++ would make it relatively difficult even with Emscripten. I would strongly encourage you (and anyone else coming across this question) file a feature request 如果这是您想要的。

也就是说,如果您打算只针对网络,我建议您尝试使用 Unity's built in JavaScript bindings to integrate directly with the Web SDK。即使对于 Web 目标,SDK 也会为您做很多繁重的工作,如果您只使用 REST,您可能不会意识到自己错过了这些工作 API.

现在,如果您只打算使用 Cloud Storage(而不是 Firestore)并且这些文件通常是您期望的 public,您可以直接通过 public URL。如果你看这个例子:

// Create a reference from an HTTPS URL
// Note that in the URL, characters are URL escaped!
var httpsReference = storage.refFromURL('https://firebasestorage.googleapis.com/b/bucket/o/images%20stars.jpg');

如果 它被 public 标记为可读,您可以通过正常 UnityWebRequest 调用 获取该文件。所以上面可能变成:

UnityWebRequest www = UnityWebRequest.Get("https://firebasestorage.googleapis.com/b/bucket/o/images%20stars.jpg");
yield return www.SendWebRequest();
// ... error handling
byte[] results = www.downloadHandler.data;
// ... create a texture from the byte[] array

希望对您有所帮助,很抱歉没有更好的答案!

--帕特里克