Important
Version 2 is now in testing/alpha phase! I'm looking for volunteer testers (#11)
Previously named Unity-Embedded-App-SDK. This project has been developed for Unity 2022 or later but it should work with all the LTS versions.
Dissonity is designed for a structure similar to the nested-messages example from Discord. You may want to familiarize with that project structure first.
using UnityEngine;
using static Dissonity.Api;
public class MyScript : MonoBehaviour
{
async void Start()
{
string userId = await GetUserId();
Debug.Log($"The user's id is {userId}");
SubActivityInstanceParticipantsUpdate((data) => {
Debug.Log("Received a participants update!");
});
}
}
Note
You can implement these packages yourself, or start with the Node.js example project inside the examples folder.
This project consists of two main packages:
- Dissonity NPM
- Dissonity Unity
To use Dissonity you need a Node.js project that uses the Dissonity NPM package and a Unity project that uses the Unity package.
In the Unity project you will have access to methods that allow you to interact with the Embedded App SDK. Behind the scenes, the SDK is still in the Node.js part. Both packages share data to provide functionality.
When running the activity, your game build will be inside a nested iframe inside the Node.js client that we will call "child" (more on this later).
First of all, you need to have installed:
- Node.js
- Unity 2022 or later
- Git (recommended)
- Install the npm package with
npm install dissonity
- Inside the client's index.js, call
setupSdk
with your config (sample) - Make sure the iframe where your build will be has the id
dissonity-child
(sample) - Configure your server to send the proper content headers (sample)
That's everything you need in the Node.js client.
Notice you don't need to manually create a DiscordSDK instance.
- Go to
Window
>Package Manager
>Add package from git URL
- Install the package from
https://github.com/Furnyr/Dissonity.git?path=/unity
- Right click in the hierarchy,
Dissonity
>Discord Bridge
- You can now build your game for WebGL and put it in your nested iframe. If you're not using the example Node.js project you will need to follow the "Project configuration" guide below.
If you don't know how to test your activity refer to the Discord documentation.
Important
If you don't add the Discord Bridge object to your scene you won't be able to receive data from the SDK!
There are code samples and an example Node.js project (using Colyseus for multiplayer support!) inside the examples folder.
If you find a bug, don't hesitate to open an issue. Now go and build something cool! :)