#nullable enable #if !UNITY_WEBGL || UNITY_EDITOR using Firebase.Storage; using System; using System.Threading; using UnityEngine; #endif public partial class FirebaseFileDownloader { #if !UNITY_WEBGL || UNITY_EDITOR public static void DownloadFileFirebaseVanilla( string targetStorageUrl, string localUrl, Action? progressCallBack = null, Action? finishCallback = null, Action? errorCallback = null ) { Debug.Log("Downloading file... from " + targetStorageUrl); FirebaseStorage storage = FirebaseStorage.DefaultInstance; StorageReference storageRef = storage.GetReferenceFromUrl(targetStorageUrl); storageRef.GetFileAsync(localUrl, new StorageProgress(state => { progressCallBack?.Invoke((float)state.BytesTransferred / state.TotalByteCount); }), CancellationToken.None).ContinueWith(task => { if (!task.IsFaulted && !task.IsCanceled) { Debug.Log("File downloaded."); } else { Debug.LogError("Error downloading file: " + task.Exception); errorCallback?.Invoke(task.Exception.ToString()); } finishCallback?.Invoke(); }); } public static void DownloadFileDownloadUrl( string targetStorageUrl, Action? finishCallback = null, Action? errorCallback = null ) { Console.WriteLine("Getting download URL... from " + targetStorageUrl); FirebaseStorage storage = FirebaseStorage.DefaultInstance; StorageReference storageRef = storage.GetReferenceFromUrl(targetStorageUrl); storageRef.GetDownloadUrlAsync().ContinueWith(task => { if (!task.IsFaulted && !task.IsCanceled) { string downloadUrl = task.Result.ToString(); Debug.Log("Download URL: " + downloadUrl); finishCallback?.Invoke(downloadUrl); } else { Debug.LogError("Error getting download URL: " + task.Exception); errorCallback?.Invoke(task.Exception.ToString()); } }); } #endif }