[Code Snippet (CS)] Same code debug\trace messages externally and ingame

Started by RawCode, February 14, 2017, 06:13:06 AM

Previous topic - Next topic

RawCode

1) Very simple "custom implementation" of text writter:
public class ConsoleToUnityLogWritter : System.IO.TextWriter
{

public override System.Text.Encoding Encoding
{
get { return null;}
}

public override void Write (object value)
{
Log.Warning (value.ToString ());
}

public override void Write (string value)
{
Log.Warning (value);
}

public override void WriteLine ()
{
return;
}
}


2) Entry point that will trigger only in game and does nothing on external run:

[StaticConstructorOnStartup]
public unsafe class Kagimono
{
static Kagimono()
{
Verse.LongEventHandler.QueueLongEvent (gate_Main, "gate_Main_indirect_call", false, null);
}

static public void gate_Main()
{
Console.SetOut (new ConsoleToUnityLogWritter ());
Main (null);
}


3) Somewhat done, you will need stub method "Write" for each type of data you actually want to output.