191 lines
4.0 KiB
C#
191 lines
4.0 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace DebuggingEssentials
|
|
{
|
|
public class LogEntry : CullItem
|
|
{
|
|
public static string search = string.Empty;
|
|
|
|
public static bool ignoreCasesInSearch;
|
|
|
|
public static bool showCommandLogs;
|
|
|
|
public static bool showUnityLogs;
|
|
|
|
public static bool showWarningLogs;
|
|
|
|
public static bool showErrorLogs;
|
|
|
|
public static bool showExceptionLogs;
|
|
|
|
public static bool showStack;
|
|
|
|
public static int currentId = 0;
|
|
|
|
public static LogEntry lastLog;
|
|
|
|
public string logString;
|
|
|
|
public string threadString;
|
|
|
|
public string[] stackLines;
|
|
|
|
public int stackLineCount;
|
|
|
|
public LogType logType;
|
|
|
|
public EntryType entryType;
|
|
|
|
public byte flag;
|
|
|
|
public Color color;
|
|
|
|
public int fontSize;
|
|
|
|
public FontStyle fontStyle;
|
|
|
|
public static void ResetStatic()
|
|
{
|
|
search = string.Empty;
|
|
ignoreCasesInSearch = false;
|
|
showCommandLogs = false;
|
|
showUnityLogs = (showWarningLogs = (showErrorLogs = (showExceptionLogs = (showStack = false))));
|
|
currentId = 0;
|
|
lastLog = null;
|
|
}
|
|
|
|
public LogEntry(string logString, string[] stackLines = null, LogType logType = LogType.Log, EntryType entryType = EntryType.Unity, Color color = default(Color), int fontSize = 12, FontStyle fontStyle = FontStyle.Normal, int threadId = -1)
|
|
: base(currentId++)
|
|
{
|
|
this.logString = logString;
|
|
if (entryType != EntryType.Frame)
|
|
{
|
|
CheckThread(threadId);
|
|
}
|
|
this.stackLines = stackLines;
|
|
if (stackLines != null)
|
|
{
|
|
stackLineCount = stackLines.Length;
|
|
}
|
|
else
|
|
{
|
|
stackLineCount = 0;
|
|
}
|
|
this.logType = logType;
|
|
this.entryType = entryType;
|
|
this.color = ((color == default(Color)) ? Color.white : color);
|
|
this.fontSize = fontSize;
|
|
this.fontStyle = fontStyle;
|
|
flag = 0;
|
|
if (entryType == EntryType.Frame)
|
|
{
|
|
isHeader = true;
|
|
}
|
|
}
|
|
|
|
public LogEntry(string logString, Color color, int fontSize, FontStyle fontStyle, int threadId = -1)
|
|
: base(currentId++)
|
|
{
|
|
this.logString = logString;
|
|
if (entryType != EntryType.Frame)
|
|
{
|
|
CheckThread(threadId);
|
|
}
|
|
this.color = color;
|
|
this.fontSize = fontSize;
|
|
this.fontStyle = fontStyle;
|
|
flag = 0;
|
|
stackLines = null;
|
|
stackLineCount = 0;
|
|
logType = LogType.Log;
|
|
entryType = EntryType.Console;
|
|
}
|
|
|
|
private void CheckThread(int threadId)
|
|
{
|
|
if (threadId == -1)
|
|
{
|
|
threadId = HtmlDebug.GetThreadId();
|
|
}
|
|
if (threadId != -1 && threadId != HtmlDebug.mainThreadId)
|
|
{
|
|
threadString = " [Thread " + threadId + "]";
|
|
}
|
|
}
|
|
|
|
public override DrawResult DoDraw()
|
|
{
|
|
if (entryType == EntryType.Frame)
|
|
{
|
|
bool flag = false;
|
|
if ((this.flag & 1) != 0 && showUnityLogs)
|
|
{
|
|
flag = true;
|
|
}
|
|
else if ((this.flag & 2) != 0 && showWarningLogs)
|
|
{
|
|
flag = true;
|
|
}
|
|
else if ((this.flag & 4) != 0 && showErrorLogs)
|
|
{
|
|
flag = true;
|
|
}
|
|
else if ((this.flag & 8) != 0 && showExceptionLogs)
|
|
{
|
|
flag = true;
|
|
}
|
|
else if ((this.flag & 0x10) != 0 && showCommandLogs)
|
|
{
|
|
flag = true;
|
|
}
|
|
if (flag)
|
|
{
|
|
if (lastLog != null && lastLog.entryType == EntryType.Frame)
|
|
{
|
|
return DrawResult.DrawHeaderAndRemoveLastHeader;
|
|
}
|
|
lastLog = this;
|
|
return DrawResult.DrawHeader;
|
|
}
|
|
return DrawResult.DontDraw;
|
|
}
|
|
if (search.Length > 0)
|
|
{
|
|
if (ignoreCasesInSearch)
|
|
{
|
|
if (logString.IndexOf(search, StringComparison.CurrentCultureIgnoreCase) == -1)
|
|
{
|
|
return DrawResult.DontDraw;
|
|
}
|
|
}
|
|
else if (logString.IndexOf(search) == -1)
|
|
{
|
|
return DrawResult.DontDraw;
|
|
}
|
|
}
|
|
lastLog = this;
|
|
return DrawResult.Draw;
|
|
}
|
|
|
|
public override float CalcHeight()
|
|
{
|
|
float num = fontSize + 6;
|
|
int num2 = Helper.CalcStringLines(logString);
|
|
if (num2 > 1)
|
|
{
|
|
num += (float)((fontSize + 2) * (num2 - 1));
|
|
}
|
|
if (entryType == EntryType.Frame)
|
|
{
|
|
num += 20f;
|
|
}
|
|
else if (showStack && entryType == EntryType.Unity && stackLineCount > 0)
|
|
{
|
|
num += (float)stackLineCount * ((float)RuntimeConsole.instance.stackFontSize + 6f) - 3f;
|
|
}
|
|
return num;
|
|
}
|
|
}
|
|
}
|