2017-08-02 19:31:35 +01:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class DiscordController : MonoBehaviour {
|
|
|
|
|
public DiscordRpc.RichPresence presence;
|
|
|
|
|
public string applicationId;
|
|
|
|
|
public int callbackCalls;
|
|
|
|
|
public int clickCounter;
|
2017-08-03 17:52:43 +01:00
|
|
|
|
public UnityEngine.Events.UnityEvent onConnect;
|
|
|
|
|
public UnityEngine.Events.UnityEvent onDisconnect;
|
2017-08-02 19:31:35 +01:00
|
|
|
|
|
2017-08-03 01:52:20 +01:00
|
|
|
|
DiscordRpc.EventHandlers handlers;
|
|
|
|
|
|
2017-08-02 19:31:35 +01:00
|
|
|
|
public void OnClick()
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("Discord: on click!");
|
|
|
|
|
clickCounter++;
|
|
|
|
|
|
|
|
|
|
presence.details = string.Format("Button clicked {0} times", clickCounter);
|
|
|
|
|
|
|
|
|
|
DiscordRpc.UpdatePresence(ref presence);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ReadyCallback()
|
|
|
|
|
{
|
|
|
|
|
++callbackCalls;
|
|
|
|
|
Debug.Log("Discord: ready");
|
2017-08-03 17:52:43 +01:00
|
|
|
|
onConnect.Invoke();
|
2017-08-02 19:31:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DisconnectedCallback(int errorCode, string message)
|
|
|
|
|
{
|
|
|
|
|
++callbackCalls;
|
|
|
|
|
Debug.Log(string.Format("Discord: disconnect {0}: {1}", errorCode, message));
|
2017-08-03 17:52:43 +01:00
|
|
|
|
onDisconnect.Invoke();
|
2017-08-02 19:31:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ErrorCallback(int errorCode, string message)
|
|
|
|
|
{
|
|
|
|
|
++callbackCalls;
|
|
|
|
|
Debug.Log(string.Format("Discord: error {0}: {1}", errorCode, message));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void JoinCallback(string secret)
|
|
|
|
|
{
|
|
|
|
|
++callbackCalls;
|
|
|
|
|
Debug.Log(string.Format("Discord: join ({0})", secret));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SpectateCallback(string secret)
|
|
|
|
|
{
|
|
|
|
|
++callbackCalls;
|
|
|
|
|
Debug.Log(string.Format("Discord: spectate ({0})", secret));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Start () {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Update () {
|
2017-08-03 01:52:20 +01:00
|
|
|
|
DiscordRpc.RunCallbacks();
|
2017-08-02 19:31:35 +01:00
|
|
|
|
}
|
2017-08-03 01:52:20 +01:00
|
|
|
|
|
2017-08-02 19:31:35 +01:00
|
|
|
|
void OnEnable()
|
|
|
|
|
{
|
2017-08-03 01:52:20 +01:00
|
|
|
|
Debug.Log("Discord: init");
|
2017-08-02 19:31:35 +01:00
|
|
|
|
callbackCalls = 0;
|
2017-08-03 01:52:20 +01:00
|
|
|
|
|
|
|
|
|
handlers = new DiscordRpc.EventHandlers();
|
|
|
|
|
handlers.readyCallback = ReadyCallback;
|
|
|
|
|
handlers.disconnectedCallback += DisconnectedCallback;
|
|
|
|
|
handlers.errorCallback += ErrorCallback;
|
|
|
|
|
handlers.joinCallback += JoinCallback;
|
|
|
|
|
handlers.spectateCallback += SpectateCallback;
|
2017-08-02 19:31:35 +01:00
|
|
|
|
DiscordRpc.Initialize(applicationId, ref handlers, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnDisable()
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("Discord: shutdown");
|
|
|
|
|
DiscordRpc.Shutdown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnDestroy()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|