Giter Club home page Giter Club logo

very-simple-twitch-chat's Introduction

Last release: 1.2.1 Buy in Asset Store Made for Unity Under MIT license

Very Simple Twitch Chat

A very simple plugin to connect your Unity games to the Twitch chat. It's possible to Login with just one line of code and start reading the messages. Custom settings for different environments and more complex login methods are also supported.

Table of contents

How to install

  • In Unity, navigate to Window -> PackageManager
  • In the Package Manager Window, click on the + sign in the top left corner and click on Add Package from GIT url
  • Type the repository URL in the text box: https://github.com/rothiotome/very-simple-twitch-chat.git

How to use

Import VerySimpleTwitchChat namespace in each class/script you want to use it:

using VerySimpleTwitchChat

How to Login

Simple anonymous connection

This is the easiest way to use the plugin. You can use TwitchChat.Login("Channel_name") to connect to the channel without needing a token or any settings customization.

using UnityEngine;
using VerySimpleTwitchChat;

public class TestingChat : MonoBehaviour
{
    string channelName = "RothioTome";
    void Start()
    {
        TwitchChat.Login(channelName);
    }
}

Customized premade settings

To customize the default settings got to Window -> Twitch Chat -> Setup. This will create a defaultTwitchChatSettings file in your Resources folder that will be used unless a custom one is specified.

It's possible to create new custom Twitch settings directly in your project to have multiple profiles. To create a new profile, right click in the Project window -> Create -> TwitchChatSettings. You can then use the custom Twitch Settings reference as an argument to the Login method.

using System.Collections.Generic;
using UnityEngine;
using VerySimpleTwitchChat;

public class TestingChat : MonoBehaviour
{
    [SerializeField] TwitchChatSettings customSettings;
    string channelName = "RothioTome";

    void Start()
    {
        TwitchChat.Login(channelName, customSettings);
    }
}

Chat Settings

OAuth Token

To send messages the Twitch chat, you need writting permissions. Anonymous connection is not allowed, so you need to create a new TwitchLoginInfo with a token that has writting permissions.

using System.Collections.Generic;
using UnityEngine;
using VerySimpleTwitchChat;

public class TestingChat : MonoBehaviour
{
    string channelName = "RothioTome";

    void Start()
    {
        TwitchChat.Login(channelName, new TwitchLoginInfo("Username", "OauthToken"));
    }
}

Once you are connection, you can send messages using the TwitchChat.SendChatMessage("message") static method.

How to receive chat messages

To receive the Twitch chat messages, subscribe to the onTwitchMessageReceived static delegates.

using System.Collections.Generic;
using UnityEngine;
using VerySimpleTwitchChat;

public class TestingChat : MonoBehaviour
{
    void Start()
    {
        TwitchChat.onTwitchMessageReceived += OnMessageReceived;
    }

    private void OnDestroy()
    {
        TwitchChat.onTwitchMessageReceived -= OnMessageReceived;
    }

    private void OnMessageReceived(Chatter chatter)
    {
        Debug.Log($"Message received from <color={chatter.tags.colorHex}>{chatter.tags.displayName}</color> : {chatter.message}");
    }
}

How to send chat messages

To send chat messages you can use the TwitchChat.SendChatMessage("message") static method. Sending chat messages is only available when you use OAuth connection method with a Token that has writting permissions.

Join a Second Twitch Channel

Very Simple Twitch Chat will automatically join the channel you use in the login method. However, this plugin supports multi channel join, so you will be able to Join a second channel (and virtually infinite of them) by using the TwitchChat.JoinChannel("channelName") method. To know if a message has been received in your main channel or another one, you can use the method Chatter.IsFromChannel("channelName"). To leave a channel you've previously joined, you can use the method TwitchChat.LeaveChannel("channelName).

Note: Sometimes the Channel Joined event occurs a few seconds before the messages start arriving. Please be aware of the delay

FAQ and Troubleshooting

Error adding package:

Error adding package: https://github.com/rothiotome/very-simple-twitch-chat.git. Unable to add package Git Error

A GIT client installed on your computer is required to add a Unity package using the Git address. You can download the Git client from git-scm.com.

If you don't want to install the Git client you can clone/download the repository to a specific folder and then add that folder to the package manager.

License

This project is released under the MIT License by RothioTome (2023)

very-simple-twitch-chat's People

Contributors

rothiotome avatar

Stargazers

Diego Ruiz Gil avatar Luis Eduardo Ocegueda Cortes avatar  avatar DaniCarco avatar Manu_Moral (Kreative Knowmad) avatar Joohun, Maeng avatar Sathyaraj Shettigar avatar Isabel Arrans Vega avatar  avatar sunguangdong avatar Andres Fernando avatar  avatar Pedro Gonzalez avatar  avatar Javier avatar Albano Díez de Paulino avatar Arturo avatar Valeriano A.R. avatar Tei avatar Kuroda avatar Antonio Gonzalez Gea avatar Miguel Angel avatar Pedro Sanchez avatar Christian Villegas avatar SebaJGuzman avatar Diego Martín Pérez avatar Altaskur avatar Alejandro Rodríguez avatar Dani Rodríguez avatar  avatar Jaime Crespo avatar Joe Mancera avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.