Skip to content

Instantly share code, notes, and snippets.

@EntranceJew
Created August 5, 2017 00:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EntranceJew/2b83f2c163e11dd03e28fb2ed5130a5c to your computer and use it in GitHub Desktop.
Save EntranceJew/2b83f2c163e11dd03e28fb2ed5130a5c to your computer and use it in GitHub Desktop.
check for that obs
using System.Collections.Generic;
using System.Linq;
using BeeCode.Extensions;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
namespace BBallCode.Engine {
public static class IListBee {
public static T Random<T>( this IList<T> list, int min = 0, int max = -1 ) {
if( max <= 0 ) max = list.Count;
UnityEngine.Debug.Assert( list != null, "list != null" );
UnityEngine.Debug.Assert( list.Count > 0, "list.Count > 0" );
return list[UnityEngine.Random.Range( min, max )];
}
}
public class OBSChecker : MonoBehaviour {
public AudioSource aus;
public TextMeshProUGUI textToReplace;
public List<Button> buttons = new List<Button>();
public List<string> wordList = new List<string>{
"engage",
"teenage",
"onstage",
"enrage",
"garage",
"upstage",
"ratcage",
"ice age",
"rampage",
"rain gauge"
};
public static List<string> streamSoftware = new List<string>{
"obs64",
"obs32",
"OBS",
"gameshow",
"XSplit.Gamecaster",
"XSplit.Core",
"XSplit",
"XSplit.xbcbp",
"vMix64",
"vMix",
"GameCapture", // elgato
"RECentral 3", // AVERMEDIA
"RECentral",
"Wirecast"
};
public AudioClip correctClip;
public AudioClip wrongClip;
private string _originalMessage;
private List<string> _workingList = new List<string>();
private void OnEnable() {
_originalMessage = textToReplace.text;
if( SceneManager.GetActiveScene().buildIndex == 0 && IsOBSRunning() ) {
ScrambleList();
} else {
hideIfNoOBS.SetActive( false );
}
}
private void ScrambleList() {
aus.PlayOneShot( wrongClip );
System.Diagnostics.Debug.Assert( wordList != null, "wordList != null" );
System.Diagnostics.Debug.Assert( textToReplace != null, "textToReplace != null" );
System.Diagnostics.Debug.Assert( textToReplace.text != null, "textToReplace.text != null" );
_workingList = wordList.ToList();
var wordToPick = _workingList.Random();
_workingList.Remove( wordToPick );
textToReplace.text = _originalMessage.Replace( "%s", wordToPick );
var buttonToPick = buttons.Random();
foreach( var button in buttons ) {
button.onClick.RemoveAllListeners();
var text = button.gameObject.GetComponentInChildren<TextMeshProUGUI>();
System.Diagnostics.Debug.Assert( text != null, "text != null" );
if( button == buttonToPick ) {
button.onClick.AddListener( FoundCorrectButton );
text.text = wordToPick;
} else {
button.onClick.AddListener( ScrambleList );
var selectedWord = _workingList.Random();
text.text = selectedWord;
_workingList.Remove( selectedWord );
}
}
}
private void FoundCorrectButton() {
aus.PlayOneShot( correctClip );
hideIfNoOBS.SetActive( false );
}
public static bool IsOBSRunning() {
// if this can't find the right process, make sure to double-check
// that it's the same architecture!!! x86 is not x86_64!!!
try {
foreach (var p in System.Diagnostics.Process.GetProcesses()) {
try {
if( p != null && !p.HasExited ){
foreach( var software in streamSoftware ) {
if( p.ProcessName.ToLower().StartsWith( software.ToLower() ) ) {
return true;
}
}
}
} catch(System.Exception e) {
Debug.LogError("The system said this thing was running but it lied and I don't know what it is: " + e);
}
}
} catch(System.Exception e) {
Debug.LogError("Exception caught " + e);
}
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment