DiscordController
A class in Root.Township, the global namespace.
Client: Discord Rich Presence. Shows the server, what the player is doing and where (forest, caves, town), and lets Discord friends join the server through the join secret.
- Listed in Global namespace: C to D
- Inherits or implements
MonoBehaviour
Constructors
| Member | What it is |
|---|---|
DiscordController() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
14 private and internal fields
| Member | What it is |
|---|---|
private Activity activity | The Discord activity being built. |
private ActivityManager activityManager | Discord SDK activity manager. |
private string applicationId | Discord application ID. |
private Chunk chunk | Last chunk the player was in. |
private PlayerController controller | Last local player controller seen. |
private Discord discord | The Discord SDK instance. |
private bool isActivityChanged | Set when a presence field changes, so LateUpdate sends it. |
private bool isFirstWarning | Lets the first not-running warning through once. |
private DiscordLarge largeImage | Backing field for LargeImage. |
private static Logger logger | NLog logger. |
private PlayerStateType oldState | Last player state seen. |
private DiscordSmall smallImage | Backing field for SmallImage. |
private PlayerStateManager stateManager | The local player's state manager. |
private string steamId | Steam app ID; unused here. |
Properties
| Member | What it is |
|---|---|
string Details { get; set; } | Second presence line, such as In Combat! or Exploring the Caves. |
DiscordController Instance { get; private set; } | Meant as the singleton, but it is an instance property, so the duplicate check in Start never fires. |
string JoinSecret { get; set; } | Join secret sent to Discord; the joined server's ID. |
DiscordLarge LargeImage { get; set; } | Large presence image (splash, town, forest or caves). |
string LargeImageHover { get; set; } | Hover text for the large image. |
string Server { get; set; } | Party ID sent to Discord; the joined server's name. |
DiscordSmall SmallImage { get; set; } | Small presence image. |
string SmallImageHover { get; set; } | Hover text for the small image. |
string State { get; set; } | First presence line, usually the server name. |
Methods
15 private and internal methods
| Member | What it is |
|---|---|
private void ActivityInvite(ActivityActionType type, ref User user, ref Activity activity) | Empty handler for Discord invites. |
private async void ActivityJoin(string secret) | Joins the server whose ID is in the Discord join secret. |
private void ActivityJoinRequest(ref User user) | Accepts every Discord join request. |
private void ActivitySpectate(string secret) | Empty handler for spectate. |
private void Initialize() | Applies the current player or menu state and listens for the local player being set. |
private void LateUpdate() | Runs Discord callbacks, disables itself if Discord isn't installed, and pushes the activity when it changed. |
private void Log(string log) | Logs a message with a DISCORD tag. |
private void LogCallback(LogLevel level, string message) | Forwards Discord SDK log lines to NLog at the matching level. |
private void OnDestroy() | Sets the state to Quitting and disposes the Discord SDK. |
private void PlayerUnset(NetworkEntity entity, bool isUnload = false) | Resets presence to In Menu when the local player goes away. |
private void ResultCallback(Result result) | Logs any Discord result that isn't OK. |
private void SetPlayer(IPlayer player) | Hooks the player's state changes and fills in the server name and join secret. |
private void SetState(bool isForced = false) | Rebuilds the presence text and image when the player, state or chunk changed (also checked on every move). |
private void Start() | Starts the Discord SDK, registers the launch command and hooks activity events; disables itself on failure. |
private void StateChanged(IPlayerState playerState) | Calls SetState when the player's state changes. |