One scene #
The demo is the single scene Scenes/Discord Demo (Template).unity. It has two views under one canvas, and DemoFlow shows one at a time:
| Object | Holds | Shown when |
|---|---|---|
Menu | Account, friends and lobby panels | Not in a session |
Session | The arena, the stage that spawns capsules, and the session bar | In a session |
The always-present objects are the camera (with DemoFollowCamera), the EventSystem, the Discord Social object, the Invite Prompt and the Tooltip.
The Discord Social object #
One object carries the demo’s components. Discord Social itself is a subsystem, so it is not in the scene: with the Application Id set it starts on its own, and the settings (start mode, remember sign in) are in Project Settings, Subsystems, Discord Social.
| Component | Job |
|---|---|
DemoSetupCheck | Shows a “Setup needed” box while no Application Id is set. |
PlaceholderNetwork (a DemoNetwork) | The networking seam. Replace it with your own. |
DiscordLobbySession | The lobby: create, join, leave, announce the session. |
DemoFlow | Moves between menu and session. |
Order of events #
- Play. The Discord Social subsystem initialises the client with the Application Id from Project Settings. With Remember Sign In on (the default) it uses a token store that keeps the token encrypted in PlayerPrefs, and signs in again with the saved token, refreshing it when expired. With no saved token the player presses Sign in.
- Sign in.
DiscordSocialApp.Connect()opens the browser to authorise, then Discord calls back, the client connects and the status becomes Ready.DiscordConnectionStatusreflects the status each frame.DiscordUserProfile(the “You” row) shows the local user.DiscordUserListfills with friends grouped Online and Offline.DiscordFriendRequestListfills with received and sent requests. - Create or join. Create lobby calls
DiscordLobbySession.Create, which creates a lobby with a random secret and the host’s user id in the lobby metadata (heathen.host). Join takes a secret, or the player accepts an invite. In both cases the player’s activity is set to the lobby so friends can be invited. - Invite. Invite on a friend row calls
Inviteon that user. The friend’s game showsDiscordInvitePrompt; accepting callsDiscordLobbySession.AcceptInvite, which joins using the secret from the invite. - Start session (host).
DemoFlow.StartSessioncallsDemoNetwork.StartHost(), which returns the address clients connect to. It captures the lobby members intoDemoWhitelist, thenDiscordLobbySession.StartSession(address)sends a lobby message with metadataheathen.session=startandheathen.address=<address>. The host switches to the session view. - Announcement (members).
DiscordLobbySessionreceives the message, ignores it unless it came from the host, and raisesOnSessionStarted(address).DemoFlow.HandleSessionStartedcallsDemoNetwork.StartClient(address), captures the whitelist and switches to the session view. - Session.
DemoSessionStagespawns one capsule per lobby member. The local member’s capsule hasDemoPawnenabled and the camera follows it. - Leave session.
DemoFlow.LeaveSessioncallsDemoNetwork.Stop(), clears the whitelist and returns to the menu. The lobby is kept so the group can play again. Leave lobby leaves the lobby and clears the player’s activity.
Who owns what #
- Discord owns identity, relationships, presence, the lobby and the invite.
- The Foundation (
DiscordSocialApp) owns the client, the token session and every operation. - The Toolkit components own the interface.
- Your
DemoNetworkowns the connection and the replication of the session.