Files
monde-usage-unity/Assets/Scripts/FirebaseWebStorageDownload.cs
2024-09-22 21:45:37 +02:00

51 lines
1.3 KiBLFS
C#

#nullable enable
using System;
using FirebaseWebGL.Scripts.FirebaseBridge;
using FirebaseWebGL.Scripts.Objects;
using JetBrains.Annotations;
using UnityEngine;
[Serializable]
public class FirebaseStorageResponse
{
public string url;
public string storagePath;
}
public partial class FirebaseFileDownloader
{
public static void DownloadFileFirebaseWeb(
string targetStorageUrl
)
{
FirebaseStorage.DownloadFile(
targetStorageUrl,
GameManager.singleton.gameObject.name,
"FirebaseStorageWebCallback",
"FirebaseStorageWebFallback"
);
}
public static void DownloadFileCallback(string response)
{
FirebaseStorageResponse storageResponse = JsonUtility.FromJson<FirebaseStorageResponse>(response);
string storagePath = storageResponse.storagePath;
string url = storageResponse.url;
VideoAsset videoAsset = GameManager.singleton.VideoDownloader.VideoAssets.Find(v => v.StorageUrl == storagePath);
if (videoAsset == null) throw new Exception("VideoAsset not found");
videoAsset.SetDownloadUrl(url);
Debug.Log($"added link from {storagePath} to {url}");
}
public static void DownloadFileFallback(string response)
{
FirebaseError firebaseError = JsonUtility.FromJson<FirebaseError>(response);
Debug.LogError("Error downloading file: " + firebaseError.message);
}
}