Ejemplo n.º 1
0
    public void WorldLeaderboardForRubbish()
    {
        PlayFabClientAPI.GetLeaderboard(new GetLeaderboardRequest {
            StartPosition = 0, StatisticName = "RubbishCollected", MaxResultsCount = 10
        },
                                        result =>
        {
            foreach (PlayerLeaderboardEntry player in result.Leaderboard)
            {
                GameObject obj = Instantiate(listingPrefab, leaderboardPanel.transform);
                LeaderboardListing leaderboardListing = obj.GetComponent <LeaderboardListing>();

                if (player.Position % 2 == 0)
                {
                    obj.GetComponent <Image>().color = leaderboardListing.evenColor;
                }
                else if (player.Position % 2 != 0)
                {
                    obj.GetComponent <Image>().color = leaderboardListing.oddColor;
                }
                leaderboardListing.positionText.text   = (player.Position + 1).ToString();
                leaderboardListing.playerNameText.text = player.DisplayName;
                GetPlayersCountry(player.PlayFabId, leaderboardListing);
                leaderboardListing.rubbishText.text = player.StatValue.ToString();
            }
        },
                                        error => Debug.LogError(error.GenerateErrorReport()));
        worldPlayer = true;
    }
Ejemplo n.º 2
0
    void OnGetLeadboard(GetLeaderboardResult result)
    {
        leaderboardPanel.SetActive(true);

        //  Debug.Log(result.Leaderboard[0].StatValue);
        foreach (PlayerLeaderboardEntry player in result.Leaderboard)
        {
            GameObject         tempListing = Instantiate(listingPrefab, listingContainer);
            LeaderboardListing LL          = tempListing.GetComponent <LeaderboardListing>();
            LL.playerNameText.text  = player.DisplayName;
            LL.PlayerScoreText.text = player.StatValue.ToString();
            Debug.Log(player.DisplayName + ": " + player.StatValue);
        }
    }
    /// <summary>
    /// populates with player display name and score value
    /// </summary>
    /// <param name="result"></param>
    private void OnGetLeaderBoard(GetLeaderboardResult result)
    {
        leaderboardPanel.SetActive(true);
        mainMenuItems.SetActive(false);

        for (int i = 0; i < 100; i++)
        {
            if (i < result.Leaderboard.Count)
            {
                PlayerLeaderboardEntry player = result.Leaderboard[i];


                GameObject         tempListing        = Instantiate(listingPrefab, listingContainer);
                LeaderboardListing leaderboardListing = tempListing.GetComponent <LeaderboardListing>();
                LeaderboardListing playerStatsListing = playerLeaderboardListing.GetComponent <LeaderboardListing>();

                if (player.DisplayName == null)
                {
                    Destroy(tempListing);
                    debugReporter.text = debugReporter.text + "\n" + "Null player name destroyed";
                }
                else
                {
                    if (player.PlayFabId == Auth.playFabId)
                    {
                        playerStatsListing.playerName.text  = player.DisplayName.ToString();
                        playerStatsListing.playerScore.text = player.StatValue.ToString();
                        playerStatsListing.playerRank.text  = (player.Position + 1).ToString();

                        leaderboardListing.playerName.text  = player.DisplayName.ToString();
                        leaderboardListing.playerScore.text = player.StatValue.ToString();
                        leaderboardListing.playerRank.text  = (player.Position + 1).ToString();

                        leaderboardListing.playerName.font  = currentUserDisplayFont;
                        leaderboardListing.playerScore.font = currentUserDisplayFont;
                        leaderboardListing.playerRank.font  = currentUserDisplayFont;
                    }
                    else
                    {
                        leaderboardListing.playerName.text  = player.DisplayName.ToString();
                        leaderboardListing.playerScore.text = player.StatValue.ToString();
                        leaderboardListing.playerRank.text  = (player.Position + 1).ToString();
                    }
                }
            }
        }

        loadingAnimation.SetActive(false);
    }
Ejemplo n.º 4
0
 public void GetPlayersCountry(string playerId, LeaderboardListing ll)
 {
     PlayFabClientAPI.GetUserData(new PlayFab.ClientModels.GetUserDataRequest()
     {
         PlayFabId = playerId
     },
                                  result =>
     {
         if (result.Data.ContainsKey("Country"))
         {
             ll.countryText.text = result.Data["Country"].Value;
         }
     },
                                  error => Debug.LogError(error.GenerateErrorReport()));
 }
Ejemplo n.º 5
0
    void RPCUpdateLeaderboard(Player player)
    {
        LeaderboardListing newListing = Instantiate(leaderBoardListing, leaderBoardListingTransform).GetComponent <LeaderboardListing>();

        newListing.nameText.text = player.NickName;
        leaderBoardList.Add(player);

        newListing.positionText.text = leaderBoardList.Count + "";
        Random.InitState(player.ActorNumber);

        newListing.setTextColor(new Color(Random.value, Random.value, Random.value));
        if (player != PhotonNetwork.LocalPlayer)
        {
            messagePanel.printMessage(player.NickName + " has reached finish with position " + leaderBoardList.Count);
        }
    }
Ejemplo n.º 6
0
    void OnGetLeaderboard(GetLeaderboardResult Resultado)
    {
        leaderboardPanel.SetActive(true);
        //Debug.Log(Resultado.Leaderboard[0].StatValue);


        // Lista de repetição para ser chamada sempre que necessário.
        foreach (PlayerLeaderboardEntry player in Resultado.Leaderboard)
        {
            //player.DisplayName = GameController.myPlayername.text;

            // Gera um GameObject para ser uma lista temporaria que vai receber um prefab
            GameObject tempListing = Instantiate(listingPrefab, listingContainer);
            // Esse prefab vai exibir a lista do leaderboard e substituir o texto pelos valores do servidor.
            LeaderboardListing LL = tempListing.GetComponent <LeaderboardListing>();
            LL.playerNameText.text  = player.DisplayName;
            LL.playerScoreText.text = player.StatValue.ToString();
            Debug.Log(player.DisplayName + ":" + player.StatValue);
        }
    }
Ejemplo n.º 7
0
    private IEnumerator PlayersProgressInWorldAndCitiesResults(string statName, string place, string whatToLookFor)
    {
        yield return(new WaitForSeconds(0.1f));

        int i = 0;
        var requestLeaderboard = new GetLeaderboardRequest {
            StatisticName = statName
        };

        PlayFabClientAPI.GetLeaderboard(requestLeaderboard, result =>
        {
            foreach (PlayerLeaderboardEntry player in result.Leaderboard)
            {
                if (player.PlayFabId == playerID)
                {
                    string getCountry = GetCountryFromPlace(place);
                    if (!getCountry.Contains("United Kingdom") && whatToLookFor.Contains("world"))
                    {
                        i++;
                        GameObject obj = Instantiate(listingPrefab, leaderboardPanel.transform);
                        LeaderboardListing leaderboardListing  = obj.GetComponent <LeaderboardListing>();
                        leaderboardListing.positionText.text   = (player.Position + 1).ToString();
                        leaderboardListing.playerNameText.text = place;
                        leaderboardListing.countryText.text    = getCountry;
                        leaderboardListing.rubbishText.text    = player.StatValue.ToString();
                    }
                    else if (getCountry.Contains("United Kingdom") && whatToLookFor.Contains("cities"))
                    {
                        GameObject obj = Instantiate(listingPrefab, leaderboardPanel.transform);
                        LeaderboardListing leaderboardListing  = obj.GetComponent <LeaderboardListing>();
                        leaderboardListing.positionText.text   = (player.Position + 1).ToString();
                        leaderboardListing.playerNameText.text = place;
                        leaderboardListing.countryText.text    = getCountry;
                        leaderboardListing.rubbishText.text    = player.StatValue.ToString();
                    }
                }
            }
        },
                                        error => Debug.LogError(error.GenerateErrorReport()));
    }
Ejemplo n.º 8
0
    public void PlayersCountryLeaderboardResults(string playerCountry)
    {
        var requestLeaderboard = new GetLeaderboardRequest {
            StartPosition = 0, StatisticName = playerCountry, MaxResultsCount = 10
        };

        PlayFabClientAPI.GetLeaderboard(requestLeaderboard, result =>
        {
            if (result.Leaderboard.Count == 0)
            {
                GameObject obj = Instantiate(listingPrefab, leaderboardPanel.transform);
                LeaderboardListing leaderboardListing  = obj.GetComponent <LeaderboardListing>();
                leaderboardListing.positionText.text   = "1";
                leaderboardListing.playerNameText.text = playerName;
                leaderboardListing.countryText.text    = playerCountry.Replace(" isCountry", "");
                leaderboardListing.rubbishText.text    = playerInfo.PlayerRubbish.ToString();
            }
            foreach (PlayerLeaderboardEntry player in result.Leaderboard)
            {
                GameObject obj = Instantiate(listingPrefab, leaderboardPanel.transform);
                LeaderboardListing leaderboardListing = obj.GetComponent <LeaderboardListing>();
                if (player.Position % 2 == 0)
                {
                    obj.GetComponent <Image>().color = leaderboardListing.evenColor;
                }
                else if (player.Position % 2 != 0)
                {
                    obj.GetComponent <Image>().color = leaderboardListing.oddColor;
                }
                leaderboardListing.positionText.text   = (player.Position + 1).ToString();
                leaderboardListing.playerNameText.text = player.DisplayName;
                leaderboardListing.countryText.text    = playerCountry.Replace(" isCountry", "");
                leaderboardListing.rubbishText.text    = player.StatValue.ToString();
            }
        },
                                        error => Debug.LogError(error.GenerateErrorReport()));
        OnDataRetrieved();
    }
    /// <summary>
    /// Also displays the player in the end if player is not found in top 100
    /// </summary>
    /// <param name="result"></param>
    private void OnGetLeaderBoardAroundPlayer(GetLeaderboardAroundPlayerResult result)
    {
        debugReporter.text = debugReporter.text + "\n" + "OnGetLeaderBoardAroundPlayer() : Success leaderboard retrieve";

        PlayerLeaderboardEntry player = new PlayerLeaderboardEntry();

        for (int i = 0; i < result.Leaderboard.Count; i++)
        {
            if (Auth.playFabId == result.Leaderboard[i].PlayFabId.ToString())
            {
                player = result.Leaderboard[i];
                PlayerPrefs.SetInt(PlayerPrefsStrings.playerAccountHighscore, player.StatValue);
            }
        }

        LeaderboardListing playerStatsListing = playerLeaderboardListing.GetComponent <LeaderboardListing>();

        playerStatsListing.playerName.text  = player.DisplayName.ToString();
        playerStatsListing.playerScore.text = player.StatValue.ToString();
        playerStatsListing.playerRank.text  = (player.Position + 1).ToString();

        loadingAnimation.SetActive(false);
    }
Ejemplo n.º 10
0
    public IEnumerator GetWorldLeaderboardByTeam()
    {
        var idTeamnameRubbish = new Trictionary();

        PlayFabAdminAPI.GetPlayersInSegment(
            new GetPlayersInSegmentRequest {
            SegmentId = "CAD8FCF4CF87AD8E"
        },
            result =>
        {
            foreach (var item in result.PlayerProfiles)
            {
                idTeamnameRubbish.Add(item.PlayerId, "-", 0);
            }
        },
            error => Debug.LogError(error.GenerateErrorReport()));
        yield return(new WaitForSeconds(6));

        foreach (var id in idTeamnameRubbish.Keys)
        {
            PlayFabClientAPI.GetUserData(
                new PlayFab.ClientModels.GetUserDataRequest {
                PlayFabId = id
            },
                result =>
            {
                idTeamnameRubbish[id] = new TeamNameRubbish
                {
                    Value1 = result.Data["TeamName"].Value
                };
            },
                error => Debug.LogError(error.GenerateErrorReport()));
        }
        yield return(new WaitForSeconds(4f));

        Dictionary <string, int> idRubbish = new Dictionary <string, int>();

        foreach (var id in idTeamnameRubbish.Keys)
        {
            PlayFabClientAPI.GetLeaderboard(
                new GetLeaderboardRequest {
                StatisticName = "RubbishCollected"
            },
                result =>
            {
                foreach (var ldb in result.Leaderboard)
                {
                    if (ldb.PlayFabId == id)
                    {
                        idTeamnameRubbish[id] = new TeamNameRubbish
                        {
                            Value1 = idTeamnameRubbish[id].Value1,
                            Value2 = ldb.StatValue
                        };
                    }
                }
            },
                error => Debug.LogError(error.GenerateErrorReport()));
        }
        yield return(new WaitForSeconds(2f));

        Dictionary <string, int> results = new Dictionary <string, int>();

        foreach (var item in idTeamnameRubbish)
        {
            if (!results.ContainsKey(item.Value.Value1))
            {
                results.Add(item.Value.Value1, item.Value.Value2);
            }
            else
            {
                results[item.Value.Value1] += item.Value.Value2;
            }
        }
        var orderResults = results.OrderByDescending(key => key.Value);


        for (int i = 0; i < orderResults.Count(); i++)
        {
            GameObject         obj = Instantiate(listingPrefab, leaderboardPanel.transform);
            LeaderboardListing leaderboardListing = obj.GetComponent <LeaderboardListing>();
            if (i % 2 == 0)
            {
                obj.GetComponent <Image>().color = leaderboardListing.evenColor;
            }
            else if (i % 2 != 0)
            {
                obj.GetComponent <Image>().color = leaderboardListing.oddColor;
            }
            leaderboardListing.positionText.text   = (i + 1).ToString();
            leaderboardListing.playerNameText.text = orderResults.ElementAt(i).Key;
            leaderboardListing.rubbishText.text    = orderResults.ElementAt(i).Value.ToString();
        }
        worldTeam = true;
    }
Ejemplo n.º 11
0
    public IEnumerator GetWorldLeaderboardByCountry()
    {
        Dictionary <string, string> idCountry = new Dictionary <string, string>();

        PlayFabAdminAPI.GetPlayersInSegment(
            new GetPlayersInSegmentRequest {
            SegmentId = "CAD8FCF4CF87AD8E"
        },
            result =>
        {
            foreach (var item in result.PlayerProfiles)
            {
                idCountry.Add(item.PlayerId, "");
            }
        },
            error => Debug.LogError(error.GenerateErrorReport()));

        yield return(new WaitForSeconds(3));

        foreach (var id in idCountry.Keys)
        {
            PlayFabClientAPI.GetUserData(
                new PlayFab.ClientModels.GetUserDataRequest {
                PlayFabId = id
            },
                result =>
            {
                if (idCountry.ContainsKey(id))
                {
                    idCountry[id] = result.Data["Country"].Value;
                }
            },
                error => Debug.LogError(error.GenerateErrorReport()));
        }
        yield return(new WaitForSeconds(2));

        Dictionary <string, int> countryRubbish = new Dictionary <string, int>();
        Dictionary <string, int> countryPlayers = new Dictionary <string, int>();

        foreach (var id in idCountry.Keys)
        {
            PlayFabClientAPI.GetLeaderboardAroundPlayer(
                new GetLeaderboardAroundPlayerRequest {
                PlayFabId = id, StatisticName = idCountry[id] + " isCountry"
            },
                result =>
            {
                int index = result.Leaderboard.FindIndex(pl => pl.PlayFabId == id);
                if (!countryRubbish.ContainsKey(idCountry[id]))
                {
                    countryRubbish.Add(idCountry[id], result.Leaderboard[index].StatValue);
                    countryPlayers.Add(idCountry[id], 1);
                }
                else
                {
                    countryRubbish[idCountry[id]] += result.Leaderboard[index].StatValue;
                    countryPlayers[idCountry[id]]++;
                }
            },
                error => Debug.LogError(error.GenerateErrorReport()));
        }
        yield return(new WaitForSeconds(1));

        var orderCountryRubbish = countryRubbish.OrderByDescending(key => key.Value);

        for (int i = 0; i < orderCountryRubbish.Count(); i++)
        {
            GameObject         obj = Instantiate(listingPrefab, leaderboardPanel.transform);
            LeaderboardListing leaderboardListing = obj.GetComponent <LeaderboardListing>();
            if (i % 2 == 0)
            {
                obj.GetComponent <Image>().color = leaderboardListing.evenColor;
            }
            else if (i % 2 != 0)
            {
                obj.GetComponent <Image>().color = leaderboardListing.oddColor;
            }
            leaderboardListing.positionText.text   = (i + 1).ToString();
            leaderboardListing.playerNameText.text = orderCountryRubbish.ElementAt(i).Key;

            int val = 0;
            foreach (var k in countryPlayers)
            {
                if (k.Key == orderCountryRubbish.ElementAt(i).Key)
                {
                    val = k.Value;
                }
            }

            leaderboardListing.countryText.text = val.ToString();
            leaderboardListing.rubbishText.text = orderCountryRubbish.ElementAt(i).Value.ToString();
        }
        worldCountries = true;
    }
Ejemplo n.º 12
0
using System.Collections.Generic;
using Photon.Pun;
using PlayFab;
using PlayFab.ClientModels;
using PlayFab.Json;
using UnityEngine;
using UnityEngine.SceneManagement;

public class PlayFabController : MonoBehaviour
{
    public static PlayFabController PFC;

    private string userEmail;
    private string userPassword;
    private string username;
    public GameObject loginPanel;
    public GameObject addLoginPanel;
    public GameObject recoverButton;
    public SceneManager SM;

    private void OnEnable() {
        if (PlayFabController.PFC == null) {
            PlayFabController.PFC = this;
        }
        else { 
            if (PlayFabController.PFC != this) {
                Destroy(this.gameObject);
            }
        }
        DontDestroyOnLoad(this.gameObject);
    }

    public void Start()
    {
        //Used currently to counteract the autologin setting
        PlayerPrefs.DeleteAll();

        //Note: Setting title Id here can be skipped if you have set the value in Editor Extensions already.
        if (string.IsNullOrEmpty(PlayFabSettings.TitleId))
        {
            PlayFabSettings.TitleId = "E5D9";
        }
        //var request = new LoginWithCustomIDRequest { CustomId = "GettingStartedGuide", CreateAccount = true };
        //PlayFabClientAPI.LoginWithCustomID(request, OnLoginSuccess, OnLoginFailure);


        if (PlayerPrefs.HasKey("EMAIL"))
        {
            userEmail = PlayerPrefs.GetString("EMAIL");
            userPassword = PlayerPrefs.GetString("PASSWORD");
            var request = new LoginWithEmailAddressRequest { Email = userEmail, Password = userPassword };
            PlayFabClientAPI.LoginWithEmailAddress(request, OnLoginSuccess, OnLoginFailure);
        }
        else {
#if UNITY_ANDROID
            var requestAndroid = new LoginWithAndroidDeviceIDRequest { AndroidDeviceId = returnMobileID(), CreateAccount = true };
            PlayFabClientAPI.LoginWithAndroidDeviceID(requestAndroid, OnLoginMobileSuccess, OnLoginMobileFailure);
#endif
#if UNITY_IOS
            var requestIOS = new LoginWithIOSDeviceIDRequest { DeviceId = returnMobileID(), CreateAccount = true };
            PlayFabClientAPI.LoginWithIOSDeviceID(requestIOS, OnLoginMobileSuccess, OnLoginMobileFailure);
#endif
        }
              
    }

    #region Login
    private void OnLoginSuccess(LoginResult result)
    {
        Debug.Log("Login Success!");
        PlayerPrefs.SetString("EMAIL", userEmail);
        PlayerPrefs.SetString("PASSWORD", userPassword);
        loginPanel.SetActive(false);
        getStats();

        //Move the camera to reveal database and launch options
        var moveScript = GameObject.Find("Main Camera").GetComponent<CameraMove>();
        moveScript.MoveBack();
    }

    private void OnLoginMobileSuccess(LoginResult result)
    {
        Debug.Log("Mobile Login Success!");
        getStats();
        loginPanel.SetActive(false);

        //Move the camera to reveal the new input options
        var moveScript = GameObject.Find("Main Camera").GetComponent<CameraMove>();
        moveScript.MoveBack();
    }

    private void onRegisterSuccess(RegisterPlayFabUserResult result) {
        Debug.Log("Registration Success!");
        PlayerPrefs.SetString("EMAIL", userEmail);
        PlayerPrefs.SetString("PASSWORD", userPassword);

        PlayFabClientAPI.UpdateUserTitleDisplayName(new UpdateUserTitleDisplayNameRequest { DisplayName = username }, OnDisplayName, OnLoginMobileFailure);
        getStats();
        loginPanel.SetActive(false);

        //Move the camera to reveal the new input options
        var moveScript = GameObject.Find("Main Camera").GetComponent<CameraMove>();
        moveScript.MoveBack();
    }

    void OnDisplayName(UpdateUserTitleDisplayNameResult result) {
        Debug.Log(result.DisplayName + " is your new display name");
    }

    private void OnLoginFailure(PlayFabError error)
    {
        var registerRequest = new RegisterPlayFabUserRequest { Email = userEmail, Password = userPassword, Username = username};
        PlayFabClientAPI.RegisterPlayFabUser(registerRequest, onRegisterSuccess, onRegisterFailure);
    }

    private void OnLoginMobileFailure(PlayFabError error)
    {
        Debug.Log(error.GenerateErrorReport());
    }

    private void onRegisterFailure(PlayFabError error) {
        Debug.LogError(error.GenerateErrorReport());
    }

    public void GetUserEmail(string emailIn) {
        userEmail = emailIn;
    }

    public void getUserPassword(string passwordIn) {
        userPassword = passwordIn;
    }

    public void getUsername(string usernameIn) {
        username = usernameIn;
    }

    public void onClickLogin() {
        var request = new LoginWithEmailAddressRequest { Email = userEmail, Password = userPassword };
        PlayFabClientAPI.LoginWithEmailAddress(request, OnLoginSuccess, OnLoginFailure);
    }

    public static string returnMobileID() {
        string deviceID = SystemInfo.deviceUniqueIdentifier;
        return deviceID;
    }

    public void openAddLogin() {
        addLoginPanel.SetActive(true);

        //Move the camera to reveal the new input options
        var moveScript = GameObject.Find("Main Camera").GetComponent<CameraMove>();
        moveScript.MoveForward();
    }

    public void onClickAddLogin() {
        addLoginPanel.SetActive(false);

        var request = new LoginWithEmailAddressRequest { Email = userEmail, Password = userPassword };
        PlayFabClientAPI.LoginWithEmailAddress(request, OnLoginSuccess, OnLoginFailure);
    }

    private void onAddLoginSuccess(AddUsernamePasswordResult result)
    {
        Debug.Log("Login Success!");
        PlayerPrefs.SetString("EMAIL", userEmail);
        PlayerPrefs.SetString("PASSWORD", userPassword);
        getStats();
        addLoginPanel.SetActive(false);

        //Move the camera to reveal the new input options
        var moveScript = GameObject.Find("Main Camera").GetComponent<CameraMove>();
        moveScript.MoveBack();
    }
    #endregion Login

    #region PlayerStats

    public int playerKillCount;

    public void setStats() { 
        PlayFabClientAPI.UpdatePlayerStatistics( new UpdatePlayerStatisticsRequest {
            // request.Statistics is a list, so multiple StatisticUpdate objects can be defined if required.
            Statistics = new List<StatisticUpdate> {
            new StatisticUpdate { StatisticName = "PlayerKillCount", Value = playerKillCount }
            }
        },
        result => { Debug.Log("User statistics updated"); },
        error => { Debug.LogError(error.GenerateErrorReport()); });
    }

    void getStats() {
        PlayFabClientAPI.GetPlayerStatistics(
            new GetPlayerStatisticsRequest(),
            OnGetStatistics,
            error => Debug.LogError(error.GenerateErrorReport())
        );
    }

    void OnGetStatistics(GetPlayerStatisticsResult result)
    {
        Debug.Log("Received the following Statistics:");
        foreach (var eachStat in result.Statistics)
        {
            Debug.Log("Statistic (" + eachStat.StatisticName + "): " + eachStat.Value);
            switch(eachStat.StatisticName) {
                case "PlayerKillCount":
                    playerKillCount = eachStat.Value;
                    break;
            }
        }
    }

    // Build the request object and access the API
    public void StartCloudUpdatePlayerStats()
    {
        PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest()
        {
            FunctionName = "UpdatePlayerStats", // Arbitrary function name (must exist in your uploaded cloud.js file)
            FunctionParameter = new { pKillCount = playerKillCount}, // The parameter provided to your function
            GeneratePlayStreamEvent = true, // Optional - Shows this event in PlayStream
        }, OnCloudUpdateStats, OnErrorShared);
    }


    private static void OnCloudUpdateStats(ExecuteCloudScriptResult result)
    {
        // Cloud Script returns arbitrary results, so you have to evaluate them one step and one parameter at a time
        Debug.Log(JsonWrapper.SerializeObject(result.FunctionResult));
        JsonObject jsonResult = (JsonObject)result.FunctionResult;
        object messageValue;
        jsonResult.TryGetValue("messageValue", out messageValue); // note how "messageValue" directly corresponds to the JSON values set in Cloud Script
        Debug.Log((string)messageValue);
    }

    private static void OnErrorShared(PlayFabError error)
    {
        Debug.Log(error.GenerateErrorReport());
    }

    #endregion PlayerStats


    public GameObject leaderboardPanel;
    public GameObject listingPrefab;
    public Transform listingContainer;

    #region Leaderboard
    public void GetLeaderboard() {
        var requestLeaderboard = new GetLeaderboardRequest { StartPosition = 0, StatisticName = "PlayerKillCount", MaxResultsCount = 20 };
        PlayFabClientAPI.GetLeaderboard(requestLeaderboard, onGetLeaderboard, onErrorLeaderboard);
    }

    void onGetLeaderboard(GetLeaderboardResult result) {
        leaderboardPanel.SetActive(true);
        //Debug.Log(result.Leaderboard[0].StatValue);
        foreach(PlayerLeaderboardEntry player in result.Leaderboard) {
            GameObject tempListing = Instantiate(listingPrefab, listingContainer);
            LeaderboardListing LL = tempListing.GetComponent<LeaderboardListing>();
            LL.playerNameText.text = player.DisplayName;
            LL.playerScoreText.text = player.StatValue.ToString();
            Debug.Log(player.DisplayName + ": " + player.StatValue);
        }
    }

    public void closeLeaderboardPanel() {
        leaderboardPanel.SetActive(false);
        for(int i = listingContainer.childCount - 1; i >= 0; i--) {
            Destroy(listingContainer.GetChild(i).gameObject);
        }
    }

    void onErrorLeaderboard(PlayFabError error) {
        Debug.LogError(error.GenerateErrorReport());
    }

    #endregion Leaderboard



    #region Friends

    string friendUsername;

    enum FriendIdType { PlayFabId, Username, Email, DisplayName };

    void AddFriend(FriendIdType idType, string friendId)
    {
        var request = new AddFriendRequest();
        switch (idType)
        {
            case FriendIdType.PlayFabId:
                request.FriendPlayFabId = friendId;
                break;
            case FriendIdType.Username:
                request.FriendUsername = friendId;
                break;
            case FriendIdType.Email:
                request.FriendEmail = friendId;
                break;
            case FriendIdType.DisplayName:
                request.FriendTitleDisplayName = friendId;
                break;
        }
        // Execute request and update friends when we are done
        PlayFabClientAPI.AddFriend(request, result => {
            Debug.Log("Friend added successfully!");
        }, DisplayPlayFabError);
    }

    List<FriendInfo> _friends = null;

    void GetFriends()
    {
        PlayFabClientAPI.GetFriendsList(new GetFriendsListRequest
        {
            IncludeSteamFriends = false,
            IncludeFacebookFriends = false
        }, result => {
            _friends = result.Friends;
            DisplayFriends(_friends); // triggers your UI
        }, DisplayPlayFabError);
    }

    void DisplayFriends(List<FriendInfo> friendsCache) { friendsCache.ForEach(f => Debug.Log(f.Username)); }
    void DisplayPlayFabError(PlayFabError error) { Debug.Log(error.GenerateErrorReport()); }
    void DisplayError(string error) { Debug.LogError(error); }

    public void OnClickAddFriend() {
        AddFriend(FriendIdType.Username, friendUsername);
    }

    public void setFriendUsername(string value) {
        friendUsername = value;
    }

    #endregion Friends
}