Exemple #1
0
    public static void SetScore(int newScore, bool isHard)
    {
        if (isHard)
        {
            DatabaseReference reference = PlayerInformation.GetDatabaseReference()
                                          .Child("user")
                                          .Child(PlayerInformation.auth.CurrentUser.UserId)
                                          .Child("score");

            Score  score     = new Score(newScore, GetTimestamp());
            string jsonScore = JsonUtility.ToJson(score);

            reference.SetRawJsonValueAsync(jsonScore);
        }
        else
        {
            DatabaseReference reference = PlayerInformation.GetDatabaseReference()
                                          .Child("user")
                                          .Child(PlayerInformation.auth.CurrentUser.UserId);

            EasyScore easyScore     = new EasyScore(newScore, GetTimestamp());
            string    jsonEasyScore = JsonUtility.ToJson(easyScore);

            reference.Child("easyScore").SetRawJsonValueAsync(jsonEasyScore);
        }
    }
Exemple #2
0
    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);
                }
            }
        });
    }