Skip to content

Image Manager

Koretsky Konstantin edited this page May 11, 2020 · 5 revisions

The google play AN_ImageManager class is used to load images from the network and handles local caching for you.

Load an Image by URL

Note that this does not support arbitrary URIs - the URI must be something that was retrieved from another call to Google Play services. The result is delivered to the given callback on the main thread.

Provided URL format should be similar to the example below:

content://com.google.android.gms.games.background/images/b4d1b8fd/2956

So for example, we have the RawImage object

[SerializeField] RawImage m_userAvatar;

and we want to assign a current signed player avatar image to it. See the code sample below:

using SA.Android.GMS.Auth;
using SA.Android.GMS.Common.Images;

var client = AN_Games.GetPlayersClient();
client.GetCurrentPlayer(result => {
    if(result.IsSucceeded) {
        var player = result.Data;
        Debug.Log($"player.Id: {player.PlayerId}");
        Debug.Log($"player.DisplayName: {player.DisplayName}");
        Debug.Log($"player.HiResImageUri: {player.HiResImageUri}");
        Debug.Log($"player.IconImageUri: {player.IconImageUri}");
        Debug.Log($"player.HasIconImage: {player.HasIconImage}");
        Debug.Log($"player.HasHiResImage: {player.HasHiResImage}");
        if (!player.HasHiResImage) {
             var url = player.HiResImageUri;
             var manager = new AN_ImageManager();
             manager.LoadImage(url, imaheLoadResult => {
                  m_userAvatar.texture = imaheLoadResult.IsSucceeded ? imaheLoadResult.Image : null;
             });
        }
    } else {
        Debug.LogError($"Failed to load Current Player {result.Error.FullMessage}");
    }
});
Clone this wiki locally