Friends

Get info about player Google Play friends is pretty simple. Here is the example how you can send friends load request, and get the result. Use GooglePlayManager to make your implementation.

GooglePlayManager.ActionFriendsListLoaded +=  OnFriendListLoaded;
GooglePlayManager.Instance.LoadFriends();

private void OnFriendListLoaded(GooglePlayResult result) {
	GooglePlayManager.ActionFriendsListLoaded -=  OnFriendListLoaded;
	SA_StatusBar.text = "Load Friends Result:  " + result.Response.ToString();
}

 

As soon as friend list loaded we can get all current player friends ids using GooglePlayManager.Instance.FriendsList:

public List<string> FriendsList 

 

Also, we can get Info about player using:

GooglePlayerTemplate player=GooglePlayManager.Instance.GetPlayerById(playerId);

 

The Player is represented as GooglePlayerTemplate class.

 

Note: Plugin automatically trigger player info download after we got player id from friends load request or from any other request for example score list request. Which basically means 2 things:

  1. You do not have to send player info load request by yourself. If you got info about player id, it means plugin automatically will send player info request.
  2. The player info request can take some time, so it always good practice to check if player info exists before using it. The same with the player avatar texture.

 

Following code snippet show how you can print information about current player friends:

foreach(string fId in GooglePlayManager.Instance.FriendsList) {
    GooglePlayerTemplate p = GooglePlayManager.Instance.GetPlayerById(fId);
	if(p != null) {
        Debug.Log("playerId: " + p.PlayerId);
        Debug.Log("playerName: " + p.PlayerName);
        if(p.HasIconImage && p.Icon != null) {
			Debug.Log("hasIconImage: Yes");
		} else {
			Debug.Log("hasIconImage: No");
		}

        if(p.HasHiResImage &&  p.Image != null) {
			Debug.Log("hasImage: Yes");
		} else {
			Debug.Log("hasImage: Yes");
		}


        if(p.HasIconImage && p.Icon != null) {
			Debug.Log("Player Avatar Loaded");
		} else {
			Debug.Log("Player Avatar Not yet Loaded");
		}
	}
}

 

If you loading a lot of friends in your project, avatar textures can do a memory hit to your project. So you can disable automatic player avatars loading in plugin editor settins:

Window → Android Native → Edit Settings

 

The full use example can be founded under the FriendsLoadExample example scene.