private async static Task <LevelProgress[]> FetchDataFromFireBase() { LevelProgress[] result = null; await FireBaseDatabase.Database.Child(FireBaseSavePaths.PlayerProgressLocation()) .GetValueAsync().ContinueWith(task => { if (task.IsFaulted) { } else if (task.IsCompleted) { try { DataSnapshot snapshot = task.Result; string info = snapshot?.GetRawJsonValue()?.ToString(); if (info != null) { result = JsonHelper.FromJson <LevelProgress>(info); } } catch (Exception ex) { Debug.LogError(ex); } } }); return(result); }
public void SaveLevelProgress(LevelProgress[] levelProgress) { var toJson = JsonHelper.ToJson(levelProgress); var result = System.Threading.Tasks.Task.Run(() => FireBaseDatabase.Database.Child(FireBaseSavePaths.PlayerProgressLocation()).SetRawJsonValueAsync(toJson)); if (result.IsCanceled || result.IsFaulted) { Debug.LogWarning(result.Exception); } }