Friend Manager
Like what your seeing?
Support us as a GitHub Sponsor and get instant access to all our assets, exclusive tools and assets, escalated support and issue tracking and our gratitude. These articles are made possible by our GitHub Sponsors ... become a sponsor today!
Introduction
This tool simply exposes common features present in the API to the inspector.
This is not required to use these features it is simply a helper tool allowing user's who are more comfortable working with editor inspectors and game object rather than classic C# objects and scripting to make use of the related feature.
Namespace
Definition
Events
evtGameConnectedChatMsg
Received a message from a friend, this willy be raised if you first set the ListenForFriendsMessages to true.
The handler for this event would look like the following.
You can see the various options for EChatEntryType in Valve's documentation as linked.
evtRichPresenceUpdated
Received a notfication of rich presence change
The handler for this event would look like the following
The FriendRichPresenceUpdate_t structure is defined in Steamworks namespace space and discribes the friend ID and AppId related to the event.
evtPersonaStateChanged
Received a notification of persona state change
The handler for this event would look like the following
The PersonaStateChange_t structure is defined in the Steamworks namespace and discribes the user the change is related to as well as the changes.
Fields and Attributes
ListenForFriendsMessages
This indicates rather or not the system is listening for freind chat messages. Note that friend chat messages will only be raised in game if you set this to true.
Methods
Get Friends
Get lists of user friends, The flags argument is of type EFriendFlags and can be used to modify what subset is returned.
This is the same as calling API.Friends.Client.GetFriends(flags);
Get Coplay Friends
Gets the list of friends the user has recently played with
Get Friend Message
You should use this in responce to evtGameConnectedChatMsg to fetch the body of the message and the type of the message.
You shouldn't need to call this as we will call it for you and raise the evtGameConnectedChatMsg with the results.
SendMessage
Sends the target friend a string message. If this returns false it means the local user is rate or chat limited by Valve and cannot send a message.
How To
Create an in-game Friends List
The UI work is left up to you ... the following code will demonstrate fetching friends and how you might read the data contained within.
Note that the "Immediate" flag is your "normal" friends such as what you see in your Steam Client's friend list.
Now that we have an array of our friends we can simply iterate over that and populate our UI
Be sure to read and understand all the features of the UserData object. You can also use tools like SetUserAvatar and SetUserName to simplify fetching and keeping up to date the friend's avatar image and display name.
Create an in-game Friend Chat
The UI work is left up to you ... the following code will demonstrate enabling friend chat, listening for chat messages and sending messages to that friend.
First we should set up our event handler to listen for friend chat messages. You can do this in the Unity inspector or in code.
The handler for that would look like this
In the above example we are only paying attention to chat message types of ChatEntry. You can see all the different types here and what they mean.
Before the system will raise the evtGameConnectedChatMsg event we need to tell it to listen for messages.
Finally in order to send a friend a chat message we use the UserData of that friend. Lets assume we have a UserData named friend and that is who we want to send the message to.
We could also send the message via the friendManager such as
This is simply an example you would of course want to give the user a means to input text to send to your friend so you would likely drive this from a InputField's on submit or similar.
Last updated