public void SetMessage(DiscordRPC.Message.JoinRequestMessage message) { this.message = message; this.user = message.User; Debug.Log("Invite Received for " + message.User); //Update the username username.text = message.User.Username + "#" + message.User.Discriminator; //Update the avatar user.CacheAvatar(this, size: DiscordAvatarSize.x128, callback: (u, texture) => { Debug.Log("Downloaded Texture for Invite"); avatar.texture = texture; }); //Set our ignore start time _ignoreStartTime = Time.time; _incrementIgnoreTimer = true; }
private void OnEnable() { //Make sure we are allowed to be active. if (!active || !gameObject.activeSelf) { return; } if (!Application.isPlaying) { return; } //This has a instance already that isn't us if (_instance != null && _instance != this) { Destroy(this); return; } //Assign the instance _instance = this; DontDestroyOnLoad(this); //We are starting the client. Below is a break down of the parameters. Debug.Log("[DRP] Starting Discord Rich Presence"); _client = new DiscordRpcClient( applicationID, //The Discord Application ID steamID, //The Steam App. This can be null or empty string to disable steam intergration. registerUriScheme, //Should the client register a custom URI Scheme? This must be true for endpoints (int )targetPipe, //The target pipe to connect too new NativeNamedPipeClient() //The client for the pipe to use. Unity MUST use a NativeNamedPipeClient since its managed client is broken. ); //Update the logger to the unity logger _client.Logger = new UnityLogger() { Level = logLevel }; //Subscribe to some initial events #region Event Registration client.OnReady += (s, args) => { //We have connected to the Discord IPC. We should send our rich presence just incase it lost it. Debug.Log("[DRP] Connection established and received READY from Discord IPC. Sending our previous Rich Presence and Subscription."); //Set the user and cache their avatars _currentUser = args.User; _currentUser.CacheAvatar(this, DiscordAvatarSize.x128); }; client.OnPresenceUpdate += (s, args) => { Debug.Log("[DRP] Our Rich Presence has been updated. Applied changes to local store."); _currentPresence = (DiscordPresence)args.Presence; }; client.OnSubscribe += (s, a) => { Debug.Log("[DRP] New Subscription. Updating local store."); _currentSubscription = client.Subscription.ToUnity(); }; client.OnUnsubscribe += (s, a) => { Debug.Log("[DRP] Removed Subscription. Updating local store."); _currentSubscription = client.Subscription.ToUnity(); }; client.OnError += (s, args) => { //Something bad happened while we tried to send a event. We will just log this for clarity. Debug.LogError("[DRP] Error Occured within the Discord IPC: (" + args.Code + ") " + args.Message); }; client.OnJoinRequested += (s, args) => { Debug.Log("[DRP] Join Requested"); }; events.RegisterEvents(client); #endregion //Start the client _client.Initialize(); Debug.Log("[DRP] Discord Rich Presence intialized and connecting..."); //Set initial presence and sub. (This will enqueue it) SetSubscription(_currentSubscription); SetPresence(_currentPresence); }