using SystemCollectionsGeneric;using UnityEngine; summary A console to display Unitys debug logs in-game summarypublic class te MonoBehaviour public enum LogFilterType All Log
要将提示信息显示在错误窗口中,您可以在ConsoleWindow方法中添加一个条件语句来检查日志的类型是否为错误(Error)类型。如果是错误类型,您可以使用GUILayout.Label方法将日志消息显示为错误。
以下是修改后的ConsoleWindow方法的示例代码:
void ConsoleWindow(int windowID)
{
currentFilterType = (LogFilterType)GUILayout.SelectionGrid((int)currentFilterType, new string[] { "All", "Log", "Warning", "Error", "Exception" }, 5);
scrollPosition = GUILayout.BeginScrollView(scrollPosition);
// Iterate through the recorded logs.
for (int i = 0; i < logs.Count; i++)
{
var log = logs[i];
if (currentFilterType == LogFilterType.All || log.type.ToString() == currentFilterType.ToString())
{
// Combine identical messages if collapse option is chosen.
if (collapse)
{
var messageSameAsPrevious = i > 0 && log.message == logs[i - 1].message;
if (messageSameAsPrevious)
{
continue;
}
}
GUI.contentColor = logTypeColors[log.type];
if (log.type == LogType.Error) // Check if log type is Error
{
GUILayout.Label(log.message);
}
else if (log.type == LogType.Exception)
{
GUILayout.Label(log.message + "\n<i><color=white>" + log.stackTrace + "</color></i>");
}
else
{
GUILayout.Label(log.message);
}
}
}
GUILayout.EndScrollView();
GUI.contentColor = Color.white;
GUILayout.BeginHorizontal();
if (GUILayout.Button(clearLabel))
{
logs.Clear();
}
if (GUILayout.Button(collapseLabel))
{
collapse = !collapse;
}
GUILayout.EndHorizontal();
// Allow the window to be dragged by its title bar.
//GUI.DragWindow(titleBarRect);
}
在此示例中,我们添加了一个条件语句来检查日志类型是否为错误类型(LogType.Error)。如果是错误类型,我们使用GUILayout.Label方法将日志消息显示为错误。
现在,当您运行项目并打开控制台窗口时,只有错误类型的日志消息会显示在错误窗口中
原文地址: https://www.cveoy.top/t/topic/iCG1 著作权归作者所有。请勿转载和采集!