【发布时间】:2020-01-09 09:19:51
【问题描述】:
我正在尝试使用此示例从我的 Firebase 存储中下载和使用图像:
How to download image from firebase database, and load it into image in unity
Follow Debug 发现问题:
UnityEngine.UnityException: SupportsTextureFormatNative 只能从主线程调用。
你能提供一下,如何解决?或者,也许您可以提供不同的方式来下载和使用图像。
谢谢!
我的代码:
var firebase = FirebaseStorage.DefaultInstance;
var storageRef = firebase.GetReferenceFromUrl(_urlPics);
storageRef.Child(_resourceName).GetBytesAsync(1024*1024).ContinueWith(task =>
{
if (task.IsCompleted)
{
var texture = new Texture2D(2, 2);
byte[] fileContent = task.Result;
texture.LoadImage(fileContent);
var newRect = new Rect(0.0f, 0.0f, texture.width, texture.height);
var sprite = Sprite.Create(texture, newRect, Vector2.zero);
_image.sprite = sprite;
Debug.Log("FINISH DOWNLOAD");
}
else
{
print("DOWNLOAD WRONG");
}
});
错误抛出:
var texture = new Texture2D(2, 2);
【问题讨论】:
-
你能贴出产生这个错误的代码吗?
-
@LudovicFeltz 抱歉,只是发现这犯了一个大错误,因为该帖子显示了如何从数据库中获取链接。但我正在尝试找到如何从存储中获取图片的解决方案。但无论如何使用另一种方法都会遇到同样的问题。
-
编辑了我在主帖中的错误。
-
@HassanVoyeau 程序员对您的链接非常好的解释谢谢,非常有趣:)
标签: c# image firebase unity3d firebase-storage