private void GetOwnCloudData() { FirebaseStorage storage = FirebaseStorage.DefaultInstance; StorageReference storage_ref = storage.GetReferenceFromUrl(networkURL); string path = Directory.GetCurrentDirectory() + "\\" + folderName + "\\" + fileName; ValidateDirectory(); ValidateFile(fileName); StorageReference fileRef = storage_ref.Child($"TanabataData/{SystemInfo.deviceUniqueIdentifier}/{fileName}"); // Download to the local file system fileRef.GetFileAsync(path).ContinueWith(task => { if (!task.IsFaulted && !task.IsCanceled) { Debug.Log("User data File downloaded."); } else { Debug.Log("No user data found in cloud: " + task.Exception.ToString()); } userDataDownloaded = true; }); }
/// <summary>Call this method to load bundleList from firebase</summary> /// <example><code> /// await SourceLoader.LoadBundleList ( ).ContinueWith ( /// (task) => { /// Debug.Log ("LoadBundleListfinish"); /// bundles.AddRange (task.Result); /// } /// ); /// SourceLoader.DownloadAllBundles (bundles); ///</code></example> public async static Task <List <string> > LoadBundleList( ) { List <string> bundleList = new List <string> ( ); FirebaseStorage storage = Firebase.Storage.FirebaseStorage.DefaultInstance; StorageReference reference = storage.GetReferenceFromUrl(FirebaseConst.SheetListPath); //check local path string path = Application.persistentDataPath + "/Option"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path = Application.persistentDataPath + "/Option/SheetList.json"; //download json file Task operation = reference.GetFileAsync(path); while (!operation.IsCompleted) { await Task.Delay(1); } //load file from local BundleList textFile = JsonUtility.FromJson <BundleList> (File.ReadAllText(path)); bundleList.AddRange(textFile.bundles); return(bundleList); }
string DownloadFile(String url) { FirebaseStorage storage = FirebaseStorage.DefaultInstance; StorageReference storage_ref = storage.GetReferenceFromUrl(url); // Start downloading a file Task task = storage_ref.GetFileAsync(local_url, new Firebase.Storage.StorageProgress <DownloadState>((DownloadState state) => { DownloadingText.text = String.Format( "Progress: {0} of {1} bytes transferred.", state.BytesTransferred, state.TotalByteCount ); }), CancellationToken.None); task.ContinueWith(resultTask => { if (!resultTask.IsFaulted && !resultTask.IsCanceled) { Debug.Log("Download finished."); DownloadingText.text = "DOWnload Finished"; } }); return(local_url); }
public async static Task DownloadVideo(string netPath, string fileName) { string localPath = Application.persistentDataPath + "/Bundle/" + fileName; FirebaseStorage storage = Firebase.Storage.FirebaseStorage.DefaultInstance; StorageReference reference = storage.GetReferenceFromUrl(netPath); await reference.GetFileAsync(localPath); Debug.Log("download fin at" + localPath); }
private void GetDataFromCloud(string uID) { FirebaseStorage storage = FirebaseStorage.DefaultInstance; StorageReference storage_ref = storage.GetReferenceFromUrl(networkURL); string path = Directory.GetCurrentDirectory() + "\\" + folderName + "\\" + "TempData.txt"; ValidateDirectory(); ValidateFile("TempData.txt"); StorageReference fileRef = storage_ref.Child($"TanabataData/{uID}/{fileName}"); // Download to the local file system fileRef.GetFileAsync(path).ContinueWith(task => { if (!task.IsFaulted && !task.IsCanceled) { Debug.Log("Stranger File downloaded."); } else { Debug.Log(task.Exception.ToString()); } expectedStrangerDataCount--; if (expectedStrangerDataCount == 0) { strangerDataDownloaded = true; } List <WishData> data = JsonConvert.DeserializeObject <List <WishData> >(File.ReadAllText(path)); if (data == null) { } else if (data.Count > 1) { //WishData f**k = data[UnityEngine.Random.Range(0, data.Count)]; WishData f**k = data[0]; allWishData.Add(f**k); } else { allWishData.Add(data[0]); } }); }
public IEnumerator downloadAndSaveBlackPieces(string name, GameManager gm) { string pathToSaveIn = Application.persistentDataPath; string chessPiece = "gs://aidanharringtonunity.appspot.com/black/" + name + ".png"; storage = FirebaseStorage.DefaultInstance; // Create local filesystem URL string filename = Application.persistentDataPath + "/black.png"; StorageReference storage_ref = storage.GetReferenceFromUrl(chessPiece); // Start downloading a file Task task = storage_ref.GetFileAsync(filename, new Firebase.Storage.StorageProgress <DownloadState>((DownloadState state) => { // called periodically during the download //Debug.Log(String.Format( // "Progress: {0} of {1} bytes transferred.", // state.BytesTransferred, // state.TotalByteCount //)); }), CancellationToken.None); task.ContinueWith(resultTask => { if (!resultTask.IsFaulted && !resultTask.IsCanceled) { Debug.Log("Download black finished."); } }); Debug.Log(filename); yield return(new WaitUntil(() => task.IsCompleted)); Sprite chessPieceSprite = LoadSprite(filename); foreach (GameObject g in GameObject.FindGameObjectsWithTag(name)) { print(g.tag); g.GetComponent <SpriteRenderer>().sprite = chessPieceSprite; } yield return(null); }
public IEnumerator downloadAndSaveImage() { string pathToSaveIn = Application.persistentDataPath; string[] backgroundImages = new string[] { "gs://aidanharringtonunity.appspot.com/wood1.jpg", "gs://aidanharringtonunity.appspot.com/wood2.jpg", "gs://aidanharringtonunity.appspot.com/wood3.jpg", "gs://aidanharringtonunity.appspot.com/wood4.jpg" }; string randomBackgroundImage = backgroundImages[UnityEngine.Random.Range(0, backgroundImages.Length)]; storage = FirebaseStorage.DefaultInstance; // Create local filesystem URL string filename = Application.persistentDataPath + "/BackgroundImage.jpg"; StorageReference storage_ref = storage.GetReferenceFromUrl(randomBackgroundImage); // Start downloading a file Task task = storage_ref.GetFileAsync(filename, new Firebase.Storage.StorageProgress <DownloadState>((DownloadState state) => { // called periodically during the download //Debug.Log(String.Format( // "Progress: {0} of {1} bytes transferred.", // state.BytesTransferred, // state.TotalByteCount //)); }), CancellationToken.None); task.ContinueWith(resultTask => { if (!resultTask.IsFaulted && !resultTask.IsCanceled) { //Debug.Log("Download finished."); } }); Debug.Log(filename); yield return(new WaitUntil(() => task.IsCompleted)); Sprite backgroundImage = LoadSprite(filename); GameObject.Find("BackgroundImage").GetComponent <SpriteRenderer>().sprite = backgroundImage; yield return(null); }
public async static System.Threading.Tasks.Task DownloadFile(string URL, string localURL) { if (string.IsNullOrEmpty(URL)) { throw new ArgumentException($"'{nameof(URL)}' cannot be null or empty.", nameof(URL)); } StorageReference reference = storage.RootReference.Child(URL); // Download to the local filesystem await reference.GetFileAsync(localURL).ContinueWithOnMainThread(task => { if (!task.IsFaulted && !task.IsCanceled) { Debug.Log($"Finished downloading {URL}!"); } }); }
public void DownloadLatestMap(DownloadCallback callback) { reference.GetMetadataAsync().ContinueWith((Task <StorageMetadata> metadataTask) => { if (metadataTask.IsFaulted || metadataTask.IsCanceled) { Debug.Log("Failed to download metadata."); Debug.Log(metadataTask.Exception.InnerException.Message); } else if (metadataTask.IsCompleted) { Debug.Log("Metadata successfully downloaded."); StorageMetadata meta = metadataTask.Result; // If there's no local map or local map is old, download new map from cloud. if (!MapExists || meta.CreationTimeMillis > File.GetLastWriteTimeUtc(WorldMapPath)) { Debug.Log("Beginning map download."); DownloadInProgress = true; reference.GetFileAsync(FirebaseWorldMapPath).ContinueWith(mapTask => { DownloadInProgress = false; if (mapTask.IsFaulted || mapTask.IsCanceled) { Debug.Log("Failed to download map."); Debug.Log(mapTask.Exception.InnerException.Message); } else if (mapTask.IsCompleted) { Debug.Log("Map successfully downloaded."); callback(); } }); } else { Debug.Log("No need to download new map."); callback(); } } }); }
/// <summary>Call this method to download all bundle from firebase</summary> /// <param name="bundleList">list of bundle should load</param> public async static Task DownloadAllBundles(List <string> bundleList) { List <string> netBundles = bundleList; List <string> localBundles = new List <string> ( ); string path = Application.persistentDataPath + "/Bundle"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string [] allfile = Directory.GetFiles(path); //Find all the bundle already downloaded in the local storage foreach (string file in allfile) { //if the file doesn't have extension will be the assetbundle file if (!Path.HasExtension(file)) { localBundles.Add(file); } } //delete the bundle already downloaded from bundleList foreach (string bundle in localBundles) { int index; if ((index = netBundles.FindIndex(s => s == bundle)) != -1) { netBundles.RemoveAt(index); } } //Download other netbundles to local FirebaseStorage storage = Firebase.Storage.FirebaseStorage.DefaultInstance; List <Task> downTasks = new List <Task> ( ); //check local path path = Application.persistentDataPath + "/Bundle"; foreach (string bundle in netBundles) { StorageReference reference = storage.GetReferenceFromUrl(FirebaseConst.SheetFolderPath + "/" + bundle); path = Application.persistentDataPath + "/Bundle/" + bundle; downTasks.Add(reference.GetFileAsync(path)); } await Task.WhenAll(downTasks.ToArray( )); }
public IEnumerator downloadAndSaveImage() { string pathToSaveIn = Application.persistentDataPath; string[] backgroundImages = new string[] { "gs://jeremyattardunity.appspot.com/Background1.jpg", "gs://jeremyattardunity.appspot.com/Background2.jpg", "gs://jeremyattardunity.appspot.com/Background3.jpg", "gs://jeremyattardunity.appspot.com/Background4.jpg" }; string randomBackgroundImage = backgroundImages[UnityEngine.Random.Range(0, backgroundImages.Length)]; storage = FirebaseStorage.DefaultInstance; // Create local filesystem URL string filename = Application.persistentDataPath + "/BackgroundImage.jpg"; StorageReference storage_ref = storage.GetReferenceFromUrl(randomBackgroundImage); // Start downloading a file Task task = storage_ref.GetFileAsync(filename, new Firebase.Storage.StorageProgress <DownloadState>((DownloadState state) => { }), CancellationToken.None); task.ContinueWith(resultTask => { if (!resultTask.IsFaulted && !resultTask.IsCanceled) { } }); Debug.Log(filename); yield return(new WaitUntil(() => task.IsCompleted)); Sprite backgroundImage = LoadSprite(filename); GameObject.Find("BackgroundImage").GetComponent <SpriteRenderer>().sprite = backgroundImage; yield return(null); }
private void GetCloudItinerary() { FirebaseStorage storage = FirebaseStorage.DefaultInstance; StorageReference storage_ref = storage.GetReferenceFromUrl(networkURL); string path = Directory.GetCurrentDirectory() + "\\" + folderName + "\\" + "Itinerary.txt"; ValidateDirectory(); ValidateFile("Itinerary.txt"); StorageReference fileRef = storage_ref.Child($"TanabataData/Itinerary.txt"); // Download to the local file system fileRef.GetFileAsync(path).ContinueWith(task => { if (!task.IsFaulted && !task.IsCanceled) { Debug.Log("Itinerary downloaded."); } else { Debug.Log("Itinerary not found: " + task.Exception.ToString()); } List <string> data = JsonConvert.DeserializeObject <List <string> >(File.ReadAllText(path)); if (data == null) { itinerary = new List <string>(); } else { itinerary = data; } itineraryDataDownloaded = true; }); }
public IEnumerator DownloadAndSaveRobotic(string name) { string pathToSaveIn = Application.persistentDataPath; string piecesLoc = "gs://chadleychess.appspot.com/robot/" + name + ".png"; storage = FirebaseStorage.DefaultInstance; string filename = Application.persistentDataPath + "/black_bishop.png"; StorageReference storage_ref = storage.GetReferenceFromUrl(piecesLoc); Task task = storage_ref.GetFileAsync(filename, new Firebase.Storage.StorageProgress <DownloadState>((DownloadState state) => { Debug.Log(String.Format( "Progress: {0} of {1} bytes transferred.", state.BytesTransferred, state.TotalByteCount )); }), CancellationToken.None); task.ContinueWith(resultTask => { if (!resultTask.IsFaulted && !resultTask.IsCanceled) { Debug.Log("Traditiona Download finished."); } }); Debug.Log(filename); yield return(new WaitUntil(() => task.IsCompleted)); Sprite pawns = LoadSprite(filename); foreach (GameObject g in GameObject.FindGameObjectsWithTag(name)) { g.GetComponent <SpriteRenderer>().sprite = pawns; } yield return(null); }
public async Task DownloadReference() { string tourJsonName = "tour.json"; Debug.Log(localDLPath); // download json string localJsonPath = Path.Combine(localDLPath, tourJsonName); StorageReference childref = tourReference.Child(tourJsonName); Debug.Log("DOWNLOADING TO " + localJsonPath); await childref.GetFileAsync(localJsonPath); // download images foreach (string imgName in imgNames) { string localImgPath = Path.Combine(Application.streamingAssetsPath, imgName); localImgPath = Path.Combine(localDLPath, imgName); Debug.Log(localImgPath); await tourReference.Child(imgName).GetFileAsync(localImgPath) .ContinueWith(resultTask => { if (!resultTask.IsFaulted && !resultTask.IsCanceled) { Debug.Log("Download finished."); } else { Debug.Log(resultTask); } }); } Debug.Log("All downloads complete"); }
public IEnumerator downloadAndSave2DPieces(string name, GameManager gm) { string pathToSaveIn = Application.persistentDataPath; string chessPiece = "gs://jeremyattardunity.appspot.com/Set1/" + name + ".png"; storage = FirebaseStorage.DefaultInstance; // Create local filesystem URL string filename = Application.persistentDataPath + "/2D.png"; StorageReference storage_ref = storage.GetReferenceFromUrl(chessPiece); // Start downloading a file Task task = storage_ref.GetFileAsync(filename, new Firebase.Storage.StorageProgress <DownloadState>((DownloadState state) => { }), CancellationToken.None); task.ContinueWith(resultTask => { if (!resultTask.IsFaulted && !resultTask.IsCanceled) { } }); yield return(new WaitUntil(() => task.IsCompleted)); Sprite chessPieceSprite = LoadSprite(filename); foreach (GameObject g in GameObject.FindGameObjectsWithTag(name)) { print(g.tag); g.GetComponent <SpriteRenderer>().sprite = chessPieceSprite; } yield return(null); }
public void DownloadFile() { m_text.text = "Yükleniyor..."; storage = FirebaseStorage.GetInstance("gs://ar-demo-309912.appspot.com"); reference = storage.GetReferenceFromUrl(src); string Path = Application.persistentDataPath; if (File.Exists(Path + "/" + local)) { File.Delete(Path + "/" + local); } reference.GetFileAsync(Path + "/" + local).ContinueWithOnMainThread(task => { if (!task.IsFaulted && !task.IsCanceled) { m_text.text = ""; s_download = true; } if (task.IsFaulted) { m_text.text = "Dosyaya ulaşılamadı, böyle bir dosya olmayabilir"; } }); }
private static Task DownloadCommon(string firebaseFolder, string firebaseFileName, string destination) { StorageReference downloadReference = FirebaseStorage.DefaultInstance.RootReference.Child(firebaseFolder).Child(firebaseFileName); return(downloadReference.GetFileAsync(destination)); }
public IEnumerator downloadAndSaveImage() { if (RandomNumBG == 1) { string pathToSaveIn = Application.persistentDataPath; storage = FirebaseStorage.DefaultInstance; // Create local filesystem URL string filename = Application.persistentDataPath + "/image1.jpg"; StorageReference storage_ref = storage.GetReferenceFromUrl("gs://chadleychess.appspot.com/image1.jpg"); // Start downloading a file Task task = storage_ref.GetFileAsync(filename, new Firebase.Storage.StorageProgress <DownloadState>((DownloadState state) => { // called periodically during the download Debug.Log(String.Format( "Progress: {0} of {1} bytes transferred.", state.BytesTransferred, state.TotalByteCount )); }), CancellationToken.None); task.ContinueWith(resultTask => { if (!resultTask.IsFaulted && !resultTask.IsCanceled) { Debug.Log("Download finished."); } }); Debug.Log(filename); yield return(new WaitUntil(() => task.IsCompleted)); Sprite bgimg = LoadSprite(filename); GameObject.Find("backgroundImage").GetComponent <Image>().sprite = bgimg; } else if (RandomNumBG == 2) { string pathToSaveIn = Application.persistentDataPath; storage = FirebaseStorage.DefaultInstance; // Create local filesystem URL string filename = Application.persistentDataPath + "/image2.jpg"; StorageReference storage_ref = storage.GetReferenceFromUrl("gs://chadleychess.appspot.com/image2.jpg"); // Start downloading a file Task task = storage_ref.GetFileAsync(filename, new Firebase.Storage.StorageProgress <DownloadState>((DownloadState state) => { // called periodically during the download Debug.Log(String.Format( "Progress: {0} of {1} bytes transferred.", state.BytesTransferred, state.TotalByteCount )); }), CancellationToken.None); task.ContinueWith(resultTask => { if (!resultTask.IsFaulted && !resultTask.IsCanceled) { Debug.Log("Download finished."); } }); Debug.Log(filename); yield return(new WaitUntil(() => task.IsCompleted)); Sprite bgimg = LoadSprite(filename); GameObject.Find("backgroundImage").GetComponent <Image>().sprite = bgimg; } else if (RandomNumBG == 3) { string pathToSaveIn = Application.persistentDataPath; storage = FirebaseStorage.DefaultInstance; // Create local filesystem URL string filename = Application.persistentDataPath + "/image3.jfif"; StorageReference storage_ref = storage.GetReferenceFromUrl("gs://chadleychess.appspot.com/image3.jfif"); // Start downloading a file Task task = storage_ref.GetFileAsync(filename, new Firebase.Storage.StorageProgress <DownloadState>((DownloadState state) => { // called periodically during the download Debug.Log(String.Format( "Progress: {0} of {1} bytes transferred.", state.BytesTransferred, state.TotalByteCount )); }), CancellationToken.None); task.ContinueWith(resultTask => { if (!resultTask.IsFaulted && !resultTask.IsCanceled) { Debug.Log("Download finished."); } }); Debug.Log(filename); yield return(new WaitUntil(() => task.IsCompleted)); Sprite bgimg = LoadSprite(filename); GameObject.Find("backgroundImage").GetComponent <Image>().sprite = bgimg; } else if (RandomNumBG == 4) { string pathToSaveIn = Application.persistentDataPath; storage = FirebaseStorage.DefaultInstance; // Create local filesystem URL string filename = Application.persistentDataPath + "/image4.jpg"; StorageReference storage_ref = storage.GetReferenceFromUrl("gs://chadleychess.appspot.com/image4.jpg"); // Start downloading a file Task task = storage_ref.GetFileAsync(filename, new Firebase.Storage.StorageProgress <DownloadState>((DownloadState state) => { // called periodically during the download Debug.Log(String.Format( "Progress: {0} of {1} bytes transferred.", state.BytesTransferred, state.TotalByteCount )); }), CancellationToken.None); task.ContinueWith(resultTask => { if (!resultTask.IsFaulted && !resultTask.IsCanceled) { Debug.Log("Download finished."); } }); Debug.Log(filename); yield return(new WaitUntil(() => task.IsCompleted)); Sprite bgimg = LoadSprite(filename); GameObject.Find("backgroundImage").GetComponent <Image>().sprite = bgimg; } yield return(null); }