【发布时间】:2020-12-07 03:42:35
【问题描述】:
我目前正在开发一个 AR 应用程序,有一部分我想通过显示该地点的图像和描述来显示有关某个地理位置的信息。我想从 Firebase 检索图像和描述,但我不知道该怎么做。还有另一个场景,我想从 Firebase 云存储中检索音频文件以在场景中播放。非常感谢您的帮助!
谢谢:)
【问题讨论】:
标签: firebase unity3d firebase-realtime-database firebase-storage
我目前正在开发一个 AR 应用程序,有一部分我想通过显示该地点的图像和描述来显示有关某个地理位置的信息。我想从 Firebase 检索图像和描述,但我不知道该怎么做。还有另一个场景,我想从 Firebase 云存储中检索音频文件以在场景中播放。非常感谢您的帮助!
谢谢:)
【问题讨论】:
标签: firebase unity3d firebase-realtime-database firebase-storage
有多种方法可以从 Cloud Storage 下载文件。如果您刚刚开始,我的建议是观看 this video 概述与 Unity 的集成。
不过,您基本上可以采用三种方法:
// Download in memory, make the max size reasonable for your game
reference.GetBytesAsync(long.MaxValue).ContinueWithOnMainThread((Task<byte[]> task) => {
if (task.IsFaulted || task.IsCanceled) {
Debug.Log(task.Exception.ToString());
// Uh-oh, an error occurred!
} else {
byte[] fileContents = task.Result;
// this is needed for Unity
Texture2D tex = new Texture2D(2, 2);
tex.LoadImage(fileContents);
}
});
// Create local filesystem URL
string local_url = $"file://{Application.persistentDataPath}/imageName.jpg";
// Download to the local filesystem
reference.GetFileAsync(local_url).ContinueWithOnMainThread(task => {
if (!task.IsFaulted && !task.IsCanceled) {
Debug.Log("File downloaded.");
// load from disk later
}
});
reference.GetDownloadUrlAsync().ContinueWithOnMainThread((Task<Uri> task) => {
if (!task.IsFaulted && !task.IsCanceled) {
Debug.Log("Download URL: " + task.Result());
// ... now download the file via WWW or UnityWebRequest.
}
});
UnityWebRequest 将其拉下。【讨论】: