public static void UpdateMoney(int amount) { DatabaseReference reference = PlayerInformation.GetDatabaseReference() .Child("user") //.Child("pnRD68Js9kU5O4UNvRaPcoueTsy2") .Child(PlayerInformation.auth.CurrentUser.UserId) .Child("money"); reference.GetValueAsync().ContinueWith(task => { if (task.IsCompleted) { // Read DataSnapshot snapshot = task.Result; IDictionary data = (IDictionary)snapshot.Value; string dataMoney = data["money"].ToString(); int tmpMoney = int.Parse(dataMoney); int finalAmount = amount + tmpMoney; PlayerInformation.SoulMoney = finalAmount; // Write SoulMoney soulMoney = new SoulMoney(PlayerInformation.SoulMoney); string json = JsonUtility.ToJson(soulMoney); reference.SetRawJsonValueAsync(json); // Achievement PlayerInformation.AchievementSoul(); } }); }
public static void SetNewUserData() { string userId = PlayerInformation.auth.CurrentUser.UserId; DatabaseReference reference = PlayerInformation.GetDatabaseReference() .Child("user"); reference.GetValueAsync().ContinueWith(task => { if (task.IsCompleted) { DataSnapshot snapshot = task.Result; // New User if (!snapshot.Child(userId).Exists) { Charge charge = new Charge(GetTimestamp()); string jsonCharge = JsonUtility.ToJson(charge); Custom custom = new Custom(0, 0, 0); string jsonCustom = JsonUtility.ToJson(custom); SoulMoney soulMoney = new SoulMoney(0); string jsonMoney = JsonUtility.ToJson(soulMoney); Score score = new Score(0, GetTimestamp()); string jsonScore = JsonUtility.ToJson(score); EasyScore easyScore = new EasyScore(0, GetTimestamp()); string jsonEasyScore = JsonUtility.ToJson(easyScore); PlayNum playNum = new PlayNum(0, GetTimestamp()); string jsonPlayNum = JsonUtility.ToJson(playNum); reference.Child(userId).Child("charge").Child("boat").Child("0").SetRawJsonValueAsync(jsonCharge); reference.Child(userId).Child("charge").Child("face").Child("0").SetRawJsonValueAsync(jsonCharge); reference.Child(userId).Child("charge").Child("wave").Child("0").SetRawJsonValueAsync(jsonCharge); reference.Child(userId).Child("custom").SetRawJsonValueAsync(jsonCustom); reference.Child(userId).Child("money").SetRawJsonValueAsync(jsonMoney); reference.Child(userId).Child("score").SetRawJsonValueAsync(jsonScore); reference.Child(userId).Child("easyScore").SetRawJsonValueAsync(jsonEasyScore); reference.Child(userId).Child("playNum").SetRawJsonValueAsync(jsonPlayNum); } } }); }