Friends¶
The Beamable Friends feature allows players to connect with other players and manage friendships through various social interactions. Players can send friend invites, view pending invites, cancel invites, reject invites, accept invites, view friends, remove friends, block players, and unblock players.
The Friends feature is accessible via the BeamContext object, and is a code-first solution.
this is a list of the main concepts used in the Friends feature:
| Term | Description |
|---|---|
| Friend | A player that has accepted a friend invite from the current user. |
| Blocked Player | A player that will be prevented from sending friend invites to the current user. Blocked players cannot be friends. |
| Sent Invite | A pending invite from the current user to another player. The other player must accept the invite before the friendship can begin. |
| Received Invite | A pending invite for the current user, from another player. The user must accept the invite before the friendship can begin. |
Friends API¶
Friends can be accessed directly through the ISocialApi interface, or conveniently through the BeamContext.Social accessor. The following samples illustrate how to achieve common use cases by using the BeamContext.
Viewing Social Data¶
The BeamContext.Social returns an instance of PlayerSocial which is a serializable object you can view in the Unity inspector. The PlayerSocial object is an observable type, which means that Beamable will update it silently in the background as friendships are initiated, made, or broken.
Beamable Observables
You can use C# events to listen for changes to the PlayerSocial object. Use the ctx.Social.OnUpdated event to receive any update. The fields themselves also have events, such as ctx.Social.Friends.OnDataUpdated.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
There are 4 main resources associated with a PlayerSocial,
- The
PlayerSocial.Friendslist, which is an observable list of friends. - The
PlayerSocial.Blockedlist, which is an observable list of blocked players. - The
PlayerSocial.SentInviteslist, which is an observable list of friend invites sent from the current player. - The
PlayerSocial.ReceivedInviteslist, which is an observable list of friend invites sent to the current player.
Experiment with Multiple Beam Context objects
Validating friend invites can be hard when you're just one developer on one machine. Luckily, you can create multiple BeamContext instances at once in the same gameplay session. These samples all use BeamContext.Default for simplicity, but you can change them to use BeamContext.ForPlayer("player1"), and BeamContext.ForPlayer("player2") to simulate two unique players.
Sending an Invite¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
Accepting an Invite¶
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Removing a Friend¶
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Canceling Sent Invite¶
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Blocking a Player¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
Unblocking a Player¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
Importing Friends from Facebook¶
A player who has associated a Facebook credential with their account may automatically import Facebook friends. Facebook friends who have also linked a Facebook credential will be listed as Beamable friends. When one player imports Facebook friends, all imported friends will have the initiating player as a friend as well.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
Presence¶
A friend may have a presence object that describes the friend's online status. Friend presence is accessible directly from the PlayerFriend structure, or by using the ctx.Presence SDK.
Listening for friend presence changes¶
1 2 3 4 5 6 | |
Seting Your Current Presence¶
1 2 | |
Direct Access¶
While the previous section is the preferred way to interact with Beamable friends, you can also access the API layer directly. This approach requires much more effort to manage.
1 2 3 4 5 6 7 8 9 10 11 12 | |
