Add back Discord RPC

This commit is contained in:
2026-01-31 22:19:38 -07:00
parent e8bac521f7
commit d928fff45e
18 changed files with 809 additions and 309 deletions

View File

@@ -0,0 +1,83 @@
using DiscordRPC;
using UnityEngine;
public class DiscordRPCHandler : MonoBehaviour
{
public static DiscordRPCHandler Instance;
public DiscordRpcClient client;
private readonly Timestamps timestamp = Timestamps.Now;
private bool isIdle = false;
private string savedDetails;
private string savedState;
void Awake()
{
if (Application.isMobilePlatform || Instance != null)
{
Destroy(gameObject);
return;
}
Instance = this;
DontDestroyOnLoad(gameObject);
client = new DiscordRpcClient("1421877993176961155");
client.Initialize();
}
void OnDestroy()
{
client.Dispose();
}
void OnApplicationQuit()
{
client.Dispose();
}
void OnApplicationPause(bool pause)
{
isIdle = pause;
if (pause)
{
UpdateRPC("Idle", null, true);
}
else
{
UpdateRPC(savedDetails, savedState, true);
}
}
public void UpdateRPC(string details, string state, bool force = false)
{
if (!force && isIdle)
{
savedDetails = details;
savedState = state;
return;
}
client.SetPresence(new RichPresence
{
Details = details,
State = state,
Assets = new Assets
{
LargeImageKey = "https://games-r2.lncvrt.xyz/icons/berry-dash.png",
LargeImageText = "Berry Dash",
SmallImageKey = "https://cdn.lncvrt.xyz/pfp.png",
SmallImageText = "Made by Lncvrt!"
},
Buttons = new[]
{
new Button { Label = "Website / Download", Url = "https://games.lncvrt.xyz/game/berry-dash" },
new Button { Label = "Lncvrt Games", Url = "https://games.lncvrt.xyz" }
},
Timestamps = timestamp
});
savedDetails = details;
savedState = state;
}
}