Firebase Storage SDK无法在Unity Web Build中使用 [英] Firebase Storage SDK not working in Unity Web Build

查看:123
本文介绍了Firebase Storage SDK无法在Unity Web Build中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个使用Firebase Storage在运行时下载一些资源的项目.

I'm working on a project that uses Firebase Storage to download some resources at runtime.

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

The problem is I need to generate a web build of my app and when I try, Unity says that Firebase namespace cannot be found.

是否存在将Firebase Storage与WebGL构建一起使用的解决方法?我读过一些人说Firebase的REST API可以实现,但是我认为这不太容易,因为该项目使用了下载进度和SDK提供的其他功能.

Is there a workaround to use Firebase Storage with WebGL build? I've read people say that it is possible with the REST API of Firebase, but I don't think it is too easy, because the project uses download progress and other stuff that is given by the SDK.

很高兴知道其他一些服务(我可以在其中存储文件并在我的应用程序中下载它们)在Unity Web构建中运行良好.目前我只知道Firebase,所以我也想知道其他参考.

It would be nice to know some other services (where I can store files outside and download them within my app) that work well in Unity web build. Presently I know only Firebase, so I would like to know other references too.

推荐答案

不幸的是, Firebase Unity SDK 目前不支持网络目标.目前,即使使用Emscripten,它通过C ++进行绑定的方式也会相对困难.我强烈建议您(以及其他遇到此问题的人)提出功能请求(如果有的话)你想要的.

Unfortunately, the 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 if this is something you want.

话虽如此,如果您打算只针对网络,我建议尝试使用 Web SDK 集成一个>.即使对于Web目标,SDK也会为您带来很多繁重的负担,即使您仅使用REST API,您可能也不会意识到自己会错失良机.

That being said, if you plan to just target the web, I would recommend trying to use Unity's built in JavaScript bindings to integrate directly with the Web SDK. Even for web targets, the SDK is doing a lot of heavy lifting for you that you may not realize you're missing out on if you just use the REST API.

现在,如果您仅打算使用Cloud Storage(而不是Firestore),并且这些文件通常是公开的,则可以直接通过

Now if you're only planning on using Cloud Storage (and not, say, Firestore) and these are files that you generally expect to be public, you can just download them directly via a public URL. If you look at the example:

// 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');

您可以通过常规 UnityWebRequest 调用来抓取该文件如果被公众标记为可读.因此,上面的内容可能变为:

You can just grab that file via normal UnityWebRequest calls if it's marked as readable by the public. So the above might become:

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

我希望这会有所帮助,对不起,我没有更好的答案!

I hope this helps a little, and I'm sorry that I don't have a better answer!

-帕特里克(patrick)

--Patrick

这篇关于Firebase Storage SDK无法在Unity Web Build中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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