Skip to content

unitycoder/UnityStreamlabs

 
 

Repository files navigation

Description

Unity Streamlabs is a client for Streamlabs streaming platform, allowing to send and receive events (such as donation alerts) within Unity game engine.

Installation

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.

How to use

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);
}

Development

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.

About

Streamlabs client for Unity game engine

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%