This how-to walks you through how to use rich presence in your game.
Prerequisites
- A LootLocker account
- An existing game in the Web Console
- Rich Presence Enabled in the Web Console
- Presence Enabled in the SDK
Rich Presence
Rich Presence does not require any changes for setup in the SDK.
Sending Status Changes
When sending state changes for a player, you need to provide:
- A status name
- E.g. "main_menu", "level_1", "settings_menu"
- Metadata (Optional)
- You can include metadata when sending the state update
- E.g. "build_version", "game_fps_count"
- You can include metadata when sending the state update
Sending a Presence status is as simple as calling a function.
// Example code of a function being called when the player enters a Game Over statepublic void SendGameOverPresenceStatus(){ Dictionary<string, string> presenceDetails = new Dictionary<string, string>() { {"device", SystemInfo.deviceModel }, {"unity_version", Application.unityVersion} }; LootLockerPresenceManager.UpdatePresenceStatus("game_over", presenceDetails);}Presence uses a Websocket connection. First initialize a user session with REST for any of the authentication methods. When the user is authorized, open up a websocket connection to ws://domain_key.lootlocker.com/game/presence/v1 with the first message being:
{"token": "the_signed_in_users_session_token"}You will get back a response saying if you were authenticated or not:
{"authenticated":true}The web socket will disconnect automatically after 1 minute of no activity. We recommend to send a ping once per minute to cover any network delays or interruptions. If the Websocket is disconnected, you will need to reconnect again.
{"type":"ping"}Response:
{"type":"pong"}To send Rich Presence Statuses, send a message with the following structure:
{ "metadata": { "key1": "value1", "key2":"value2" }, "status": "game_status_to_send"}Out of Focus / Pause behaviour
When Auto Connect and Disconnect On Pause is enabled Presence will reconnect and resend the last status that was sent when Presence reconnects.
Conclusion
In this how-to we have used Rich Presence to send a change of game status. To learn how to interpret this information, continue to the View Presence in Web Console.
