Table of Contents

FriendsService

class in Coherence.Cloud

Manages friend lists from different platforms, stored in coherence Cloud.

Examples
using Coherence.Cloud;
using UnityEngine;

class FriendsList : MonoBehaviour
{
    async void Start()
    {
        // Wait until a player account has logged in to coherence Cloud.
        // The CoherenceCloudLogin component can be used for this.
        // Guest and username/password accounts cannot have friends.

        PlayerAccount playerAccount = await PlayerAccount.GetMainAsync();
        var friends = playerAccount.Services.Friends;

        friends.OnFriendAdded += friend => Debug.Log($"{friend.DisplayName} is now a friend.");
        friends.OnFriendRemoved += friend => Debug.Log($"{friend.DisplayName} is no longer a friend.");

        await friends.RefreshFriendsAsync()
            .OnFail(Debug.LogWarning)
            .OnSuccess(list => Debug.Log($"{list.Count} friend(s) also play this game."));
    }
}
Remarks

Reach it through PlayerAccount.Main.Services.Friends.

Read the friend list from the platform(s) yourself (Game Center, Steam, etc). Then, hand the ids to SyncFriendsAsync(string, IReadOnlyList<string>, CancellationToken). coherence keeps the ones that belong to players of your game and drops the rest.

Friendships go both ways: a player only appears in Friends once both sides have synced each other. coherence only mirrors external friend lists; players add/delete friends in the platform's own UI, and you have to sync the changes to Cloud afterwards.

Logging in does not fetch friends. Call SyncFriendsAsync(string, IReadOnlyList<string>, CancellationToken), or RefreshFriendsAsync(CancellationToken) if you only want to read the list. From then on coherence keeps the list current while the player is connected, raising OnFriendAdded, OnFriendRemoved and OnFriendPresenceChanged as changes come in.

Properties
Friends

The list of friends for the logged in player account.

IsDisposed

Whether the CloudService that owns this service has been disposed.

Methods
Dispose

Drops the friend list and cancels whatever was still on its way.

RefreshFriendsAsync

Fetches the player's friends from coherence Cloud, updating Friends.

SetAppearOfflineAsync

Hides the player from their friends, without logging them out.

SetPresenceAsync

Broadcasts online presence on this player account to its friends.

SyncFriendsAsync

Uploads the player's current friends from a given platform.

Events
OnFriendAdded

Raised when a new friend is acknowledged.

OnFriendPresenceChanged

Raised when a friend comes or goes, or changes what they are up to.

OnFriendRemoved

Raised when a friend is no longer.

See Also