using System.Collections.Generic; using UnityEngine; namespace MSCO { /// /// Zentrales Log der Mod: alle Meldungen landen in der MSCO-Konsole (F7), nicht in einer Loader-Konsole. /// Zusätzlich gehen sie per Debug.Log in die output_log.txt des Spiels (zur Fehlersuche), ohne dass sich die /// MSCLoader-Konsole öffnet. Thread-sicher: Meldungen aus Hintergrund-Threads werden im Hauptthread übernommen. /// public static class MscoLog { const string Prefix = "[MSCO] "; static readonly Queue pending = new Queue(); static readonly object gate = new object(); public static void Info(string text) { Add(text, ""); } public static void Warning(string text) { Add(text, "! "); } public static void Error(string text) { Add(text, "ERROR "); } static void Add(string text, string marker) { string line = Strip(text ?? ""); Debug.Log(Prefix + line); // output_log.txt lock (gate) { pending.Enqueue(marker + line); while (pending.Count > 500) pending.Dequeue(); // falls die Konsole (noch) nicht abgeholt hat } } /// Neue Meldungen abholen (Hauptthread, vom MultiplayerManager jedes Frame). public static void Drain(System.Action sink) { lock (gate) { while (pending.Count > 0) sink(pending.Dequeue()); } } static string Strip(string text) { return text.StartsWith(Prefix) ? text.Substring(Prefix.Length) : text; } } }