Ejemplo n.º 1
0
    public void OnClickLoad()
    {
        var userId = FirebaseAuthManager.Instance.UserId;

        if (userId == string.Empty)
        {
            return;
        }

        databaseRef.Child(UserDataPath).Child(userId).Child(StatsDataPath).GetValueAsync().ContinueWith(task =>
        {
            if (task.IsCanceled)
            {
                Debug.LogError("Load user data was canceled.");
                return;
            }

            if (task.IsFaulted)
            {
                Debug.LogError("Load user data encountered an error: " + task.Exception);
                return;
            }

            DataSnapshot snapshot = task.Result;
            playerStats.FromJson(snapshot.GetRawJsonValue());
            Debug.LogFormat("Load user data in successfully: {0} ({1})", "user_name", snapshot.GetRawJsonValue());
        });

        databaseRef.Child(UserDataPath).Child(userId).Child(EquipmentDataPath).GetValueAsync().ContinueWith(task =>
        {
            if (task.IsCanceled)
            {
                Debug.LogError("Load user data was canceled.");
                return;
            }

            if (task.IsFaulted)
            {
                Debug.LogError("Load user data encountered an error: " + task.Exception);
                return;
            }

            DataSnapshot snapshot = task.Result;
            playerEquipment.FromJson(snapshot.GetRawJsonValue());
            Debug.LogFormat("Load user data in successfully: {0} ({1})", "user_name", snapshot.GetRawJsonValue());
        });

        databaseRef.Child(UserDataPath).Child(userId).Child(InventoryDataPath).GetValueAsync().ContinueWith(task =>
        {
            if (task.IsCanceled)
            {
                Debug.LogError("Load user data was canceled.");
                return;
            }

            if (task.IsFaulted)
            {
                Debug.LogError("Load user data encountered an error: " + task.Exception);
                return;
            }

            DataSnapshot snapshot = task.Result;
            Debug.LogFormat("Load user data in successfully: {0} ({1})", "user_name", snapshot.GetRawJsonValue());
        });
    }