This project provides a simple integration of Twitch's EventSub API for Unity projects. It allows developers to easily incorporate Twitch events into their Unity games or applications.
TwitchManager
script to a GameObject in your Unity scene.TwitchManager
component in the Inspector.The EventSubHandler
class handles incoming Twitch events. Modify this class to implement your desired functionality for each event type.
Example:
public class EventSubHandler : MonoBehaviour, IEventHandler
{
public void OnChatMessage(Event chatEvent)
{
// Implement other functionality here
Debug.Log($"Chat message from {chatEvent.chatter_user_name}: {chatEvent.message.text}");
}
}
Helix Message Functionality Example:
public class YourClass : MonoBehaviour
{
// Assign TwitchManager first
public TwitchManager TwitchManager;
public void SendTwitchChat(string message)
{
TwitchManager.SendChatMessage(message);
TwitchManager.SendAnnouncement(message);
}
}
To test your integration without connecting to the live Twitch API, you can use the Twitch CLI mock server:
TwitchManager
component and enable the "Use Mock Server" toggle.This will direct all API calls to the local mock server instead of the live Twitch API, allowing for easier testing and development.
To setup the server:
twitch event websocket start-server
Example:
twitch event trigger channel.subscribe --transport=websocket
Feel free to modify and extend the functionality to suit your project's needs. You can add support for additional Twitch events by updating the EventSubClient
and EventSubHandler
classes.
This project is open-source and free to use in your own projects without attribution.
This is not an official Twitch product. Use at your own risk and ensure compliance with Twitch's Developer Agreement and Terms of Service.