Friends

To 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 is loaded, we can get all current player friends ids using GooglePlayManager.Instance.FriendsList:

public List<string> FriendsList 

 

Also we can get Info about a player using:

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

 

The Player is represented as GooglePlayerTemplate class.

 

Note: The plugin automatically trigger player info download after we get 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 will automatically send player info request.
  2. The player info request can take some time, so it is always a good practice to check if player info exists before using it. The same is with the player avatar texture.

 

The following code snippet shows 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 are 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 found under the FriendsLoadExample example scene.