Unity Streamlabs is a client for Streamlabs streaming platform, allowing to send and receive events (such as donation alerts) within Unity game engine.
Use UPM to install the package via the following git URL: https://github.com/Elringus/UnityStreamlabs.git?path=Assets/UnityStreamlabs
or download and import UnityStreamlabs.unitypackage manually.
After installing the package, go to project settings (Edit -> Project Settings) and select Streamlabs category.
Click "Create Streamlabs API app" and register a new app. Enter required info; specify http://localhost
for the redirect URI. Don't forget to whitelist users, that should be able to use the app.
After registering the app, enter client ID and secret to the project settings.
Now you can listen and send events in Unity, eg:
private void OnEnable ()
{
Streamlabs.Connect();
Streamlabs.OnDonation += HandleDonation;
}
private void OnDisable ()
{
Streamlabs.Disconnect();
Streamlabs.OnDonation -= HandleDonation;
}
private void HandleDonation (Donation donation)
{
Debug.Log($"Donation received: From: {donation.message[0].from} Message: {donation.message[0].message} Amount: {donation.message[0].formattedAmount}");
}
[ContextMenu("Send Donation")]
private void SendDonation ()
{
if (Streamlabs.ConnectionState == ConnectionState.Connected)
Streamlabs.SendDonation(Name, Message, Identifier, Amount, Currency);
}
Currently, only donation event is implemented. Feel free to send PRs to extend the plugin for more events.
To add a new event, add a new cs script at UnityStreamlabs/Runtime/Events
describing the data model (use Donation.cs for reference), then add corresponding event field to UnityStreamlabs/Runtime/Streamlabs.cs
static class and handle the event in HandleSocketMessage
method.
Consult Streamlabs socket API reference for available events data models.