public void SelectSegment(SegmentID id) { ShowLoader(); PlayFabAdminAPI.GetPlayersInSegment(new GetPlayersInSegmentRequest { SegmentId = id.segmentID }, result => { Debug.Log("GOT SEGMENT PLAYERS OK: " + result.ToJson().ToString()); foreach (var playerProfile in result.PlayerProfiles) { GameObject newPlayerButton = Instantiate(playerButton, Vector3.zero, Quaternion.identity, playerButton.transform.parent) as GameObject; PlayerID identity = newPlayerButton.GetComponent <PlayerID>(); identity.avatarURL = playerProfile.AvatarUrl; if (playerProfile.BannedUntil.HasValue) { identity.bannedUntil = playerProfile.BannedUntil.Value.ToLocalTime().ToString(); } else { identity.bannedUntil = "N/A"; } identity.creationDate = playerProfile.Created.Value.ToLocalTime().ToString(); identity.lastLogin = playerProfile.LastLogin.Value.ToLocalTime().ToString(); identity.displayName = playerProfile.DisplayName; foreach (var location in playerProfile.Locations) { identity.location = location.Value.City + ", " + location.Value.CountryCode; identity.latLong = location.Value.Latitude + "," + location.Value.Longitude; } string currencies = ""; foreach (var currency in playerProfile.VirtualCurrencyBalances) { currencies += "\n" + currency.Key + ": " + currency.Value; } identity.currencies = currencies; identity.originPlatform = playerProfile.Origination.Value.ToString(); identity.playerID = playerProfile.PlayerId; identity.nameText.text = playerProfile.DisplayName; newPlayerButton.SetActive(true); } DestroySegmentWindow(); playerWindow.SetActive(true); HideLoader(); }, error => { HideLoader(); Debug.LogError("ERROR GETTING SEGMENT PLAYERS: " + error.GenerateErrorReport()); Inform(error.ErrorMessage); }); }
public void GetAllPlayers() { PlayFabAdminAPI.GetPlayersInSegment( new GetPlayersInSegmentRequest { SegmentId = "CAD8FCF4CF87AD8E" }, result => { foreach (var item in result.PlayerProfiles) { if (!allPlayers.Contains(item.PlayerId)) { allPlayers.Add(item.PlayerId); } } }, error => Debug.LogError(error.GenerateErrorReport())); }
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; }
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; }