Last active
December 25, 2020 03:41
-
-
Save liortal53/aefd0322438737750e2e to your computer and use it in GitHub Desktop.
Redirect Console output to Unity's console
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.IO; | |
using System.Text; | |
using UnityEditor; | |
using UnityEngine; | |
public class ConsoleWriter : TextWriter | |
{ | |
public override void Write(char value) | |
{ | |
} | |
public override void Write(string value) | |
{ | |
Debug.Log(value); | |
} | |
public override Encoding Encoding | |
{ | |
get { return Encoding.ASCII; } | |
} | |
} | |
public class ErrorWriter : TextWriter | |
{ | |
public override void Write(char value) | |
{ | |
} | |
public override void Write(string value) | |
{ | |
Debug.LogError(value); | |
} | |
public override Encoding Encoding | |
{ | |
get { return Encoding.ASCII; } | |
} | |
} | |
[InitializeOnLoad] | |
public class ConsoleRouter | |
{ | |
static ConsoleRouter() | |
{ | |
System.Console.SetOut(new ConsoleWriter()); | |
System.Console.SetError(new ErrorWriter()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment