83 lines
2.0 KiB
C#
83 lines
2.0 KiB
C#
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;
|
|
}
|
|
} |