public async Task ReadLivesAsync() { try { await FireBaseDatabase.Database.Child(FireBaseSavePaths.PlayerLivesLocation()) .GetValueAsync().ContinueWith(task => { if (task.IsFaulted) { } else if (task.IsCompleted) { try { DataSnapshot snapshot = task.Result; string info = snapshot?.GetRawJsonValue()?.ToString(); LivesEntity result = null; if (info != null) { result = JsonUtility.FromJson <LivesEntity>(info); } LivesManager.Instance.Setup(result); } catch (Exception ex) { Debug.LogError(ex); } } }); } catch (Exception ex) { Debug.LogError(ex); } }
public void WriteLives(int livesRemaining, DateTime lastEarnedLife) { var entity = new LivesEntity() { LastEarnedLife = lastEarnedLife.ToString(), LivesRemaining = livesRemaining }; var toJson = JsonUtility.ToJson(entity); var result = System.Threading.Tasks.Task.Run(() => FireBaseDatabase.Database.Child(FireBaseSavePaths.PlayerLivesLocation()).SetRawJsonValueAsync(toJson)); if (result.IsCanceled || result.IsFaulted) { Debug.LogWarning(result.Exception); } }