Skip to content

Latest commit

 

History

History
107 lines (75 loc) · 4.05 KB

unity.md

File metadata and controls

107 lines (75 loc) · 4.05 KB

Using TwitchLib with Unity (short version)

Prerequisites:

  • Unity 2017.1+

Setup

See extensive guide to see how to compile DLL and avoid TLS problems.

Using TwitchLib with Unity (extensive version)

Prerequisites:

  • Unity 2017.1+
  • SourceTree
  • Visual Studio

Step 1 - Clone TwitchLib repository

Example with SourceTree

  • Get Repository URL by clicking the Clone or Download button. See GIF
  • Clone in SourceTree See GIF

Step 2 - Open and build project into DLLs

Example using Visual Studio

  • Open TwitchLib solution in Visual Studio See GIF
  • Set to Release mode See GIF
  • Build TwitchLib solution See GIF
  • Confirm that you now have these DLL files: See GIF
    • Newtonsoft.Json.dll
    • TwitchLib.dll
    • websocket-sharp.dll

Step 3 - Create Unity Project

  • Create new Unity project See GIF
  • In Unity select: Edit > Project Settings > Player
  • Scroll down to Api Compatibility Level and select “.NET 4.6” or higher See GIF
  • Import TwitchLib DLLs See GIF

Step 4 - Setup Twitch App

Create a twitch account for your bot

Step 5 - Setup Unity integration

TLS Fix:

public bool CertificateValidationMonoFix(System.Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
    bool isOk = true;

    if (sslPolicyErrors == SslPolicyErrors.None)
    {
        return true;
    }

    foreach (X509ChainStatus status in chain.ChainStatus)
    {
        if (status.Status == X509ChainStatusFlags.RevocationStatusUnknown)
        {
            continue;
        }

        chain.ChainPolicy.RevocationFlag = X509RevocationFlag.EntireChain;
        chain.ChainPolicy.RevocationMode = X509RevocationMode.Online;
        chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 1, 0);
        chain.ChainPolicy.VerificationFlags = X509VerificationFlags.AllFlags;

        bool chainIsValid = chain.Build((X509Certificate2)certificate);

        if (!chainIsValid)
        {
            isOk = false;
        }
    }

    return isOk;
}

Step 6 - Making your first call

Now it's just a matter of exploring the API's provided by TwitchLib and hooking into the events you need :)