playgameservices / play-games-plugin-for-unity

Google Play Games plugin for Unity
Other
3.46k stars 965 forks source link

Can I get the other players avatar/image from using the LoadScores function? when I load scores from a leaderboard? #2960

Closed nathansisler closed 3 years ago

nathansisler commented 4 years ago

You guys have well documented how to retrieve a leaderboards scores and even usernames but now I'd like to get the top players avatar/image and it doesn't seem like you support it through the social.LoadUsers function. Are you doing that on purpose? is there another way to access the image?

olehkuznetsov commented 3 years ago

social.LoadUsers should work with ids retrieved from leaderboards. Feel free to reopen if it doesn't works for you.

nathansisler commented 3 years ago

Had to run this coroutine for this to work. Might be helpful for anyone in the future.

Load scores with this :

PlayGamesPlatform.Instance.LoadScores(levelConfig, LeaderboardStart.TopScores, 1, LeaderboardCollection.Public, LeaderboardTimeSpan.AllTime, (LeaderboardScoreData data) => { curretHighScore = data.PlayerScore.value; string[] idString = new string[] { data.PlayerScore.userID }; Social.LoadUsers(idString, (users) => { highScoreUsername = users[0].userName; StartCoroutine(WaitPics(users[0])); }); });

then :

IEnumerator WaitPics(UnityEngine.SocialPlatforms.IUserProfile profile) {

    yield return new WaitUntil(() =>
    {
        return profile.image != null;
    });
    Texture2D tempTex = profile.image;
    highScoreUserImage2D.mainTexture = profile.image;
    highScoreUserImage.sprite = Sprite.Create(tempTex, new Rect(0.0f, 0.0f, tempTex.width, tempTex.height), new Vector2(0.5f, 0.5f), 100.0f);
}