InGameConsole
using UnityEngine;
using TMPro;
public class InGameConsole : MonoBehaviour
{
public TMP_Text logText;
internal string internallogString;
internal string internalstackTrace;
internal LogType internaltype;
internal bool WarningMode = true;
internal bool LogMode = true;
internal bool ErrorMode = true;
void OnEnable()
{
Application.logMessageReceived += LogCallback;
InvokeRepeating("MessageMaker",1,1);
}
void OnDisable()
{
Application.logMessageReceived -= LogCallback;
}
void MessageMaker()
{
print("Hello");
print(GameObject.Find("Object").name);
}
void LogCallback(string logString, string stackTrace, LogType type)
{
internallogString = logString;
internalstackTrace = stackTrace;
internaltype = type;
if (ErrorMode == true)
{
if (type == LogType.Exception)
{
if (!logText.text.Contains(logString)) //Check if it is already in console
{
logText.text += "<color=red>" + logString + "\r\n ******* \r\n" + stackTrace + "\r\n ------------- \r\n</color>";
}
}
}
if (LogMode == true)
{
if (type == LogType.Log)
{
if (!logText.text.Contains(logString)) //Check if it is already in console
{
logText.text += logString + "\r\n ------------- \r\n";
}
}
}
if (WarningMode == true)
{
if (type == LogType.Warning)
{
if (!logText.text.Contains(logString)) //Check if it is already in console
{
logText.text += "<color=yellow>" + logString + "\r\n ******* \r\n" + stackTrace + "\r\n ------------- \r\n</color>";
}
}
}
}
public void WarningActivation()
{
if (WarningMode == true)
{
logText.text = "";
WarningMode = false;
LogCallback(internallogString, internalstackTrace, internaltype);
return;
}
if (WarningMode == false)
{
logText.text = "";
WarningMode = true;
LogCallback(internallogString, internalstackTrace, internaltype);
return;
}
}
public void ErrorActivation()
{
if (ErrorMode == true)
{
logText.text = "";
ErrorMode = false;
LogCallback(internallogString, internalstackTrace, internaltype);
return;
}
if (ErrorMode == false)
{
logText.text = "";
ErrorMode = true;
LogCallback(internallogString, internalstackTrace, internaltype);
return;
}
}
public void LogActivation()
{
if (LogMode == true)
{
logText.text = "";
LogMode = false;
LogCallback(internallogString, internalstackTrace, internaltype);
return;
}
if (LogMode == false)
{
logText.text = "";
LogMode = true;
LogCallback(internallogString, internalstackTrace, internaltype);
return;
}
}
}