架构大更
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
@@ -6,108 +7,110 @@ using UnityEngine;
|
||||
// Container for a simple debug entry
|
||||
namespace IngameDebugConsole
|
||||
{
|
||||
public class DebugLogEntry
|
||||
{
|
||||
private const int HASH_NOT_CALCULATED = -623218;
|
||||
public class DebugLogEntry
|
||||
{
|
||||
private const int HASH_NOT_CALCULATED = -623218;
|
||||
|
||||
public string logString;
|
||||
public string stackTrace;
|
||||
private string completeLog;
|
||||
// Index of this entry among all collapsed entries
|
||||
public int collapsedIndex;
|
||||
private string completeLog;
|
||||
|
||||
// Sprite to show with this entry
|
||||
public LogType logType;
|
||||
// Collapsed count
|
||||
public int count;
|
||||
|
||||
// Collapsed count
|
||||
public int count;
|
||||
private int hashValue;
|
||||
|
||||
// Index of this entry among all collapsed entries
|
||||
public int collapsedIndex;
|
||||
public string logString;
|
||||
|
||||
private int hashValue;
|
||||
// Sprite to show with this entry
|
||||
public LogType logType;
|
||||
public string stackTrace;
|
||||
|
||||
public void Initialize( string logString, string stackTrace )
|
||||
{
|
||||
this.logString = logString;
|
||||
this.stackTrace = stackTrace;
|
||||
public void Initialize(string logString, string stackTrace)
|
||||
{
|
||||
this.logString = logString;
|
||||
this.stackTrace = stackTrace;
|
||||
|
||||
completeLog = null;
|
||||
count = 1;
|
||||
hashValue = HASH_NOT_CALCULATED;
|
||||
}
|
||||
completeLog = null;
|
||||
count = 1;
|
||||
hashValue = HASH_NOT_CALCULATED;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
logString = null;
|
||||
stackTrace = null;
|
||||
completeLog = null;
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
logString = null;
|
||||
stackTrace = null;
|
||||
completeLog = null;
|
||||
}
|
||||
|
||||
// Checks if logString or stackTrace contains the search term
|
||||
public bool MatchesSearchTerm( string searchTerm )
|
||||
{
|
||||
return ( logString != null && DebugLogConsole.caseInsensitiveComparer.IndexOf( logString, searchTerm, CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace ) >= 0 ) ||
|
||||
( stackTrace != null && DebugLogConsole.caseInsensitiveComparer.IndexOf( stackTrace, searchTerm, CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace ) >= 0 );
|
||||
}
|
||||
// Checks if logString or stackTrace contains the search term
|
||||
public bool MatchesSearchTerm(string searchTerm)
|
||||
{
|
||||
return (logString != null && DebugLogConsole.caseInsensitiveComparer.IndexOf(logString, searchTerm,
|
||||
CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace) >= 0) ||
|
||||
(stackTrace != null && DebugLogConsole.caseInsensitiveComparer.IndexOf(stackTrace, searchTerm,
|
||||
CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace) >= 0);
|
||||
}
|
||||
|
||||
// Return a string containing complete information about this debug entry
|
||||
public override string ToString()
|
||||
{
|
||||
if( completeLog == null )
|
||||
completeLog = string.Concat( logString, "\n", stackTrace );
|
||||
// Return a string containing complete information about this debug entry
|
||||
public override string ToString()
|
||||
{
|
||||
if (completeLog == null)
|
||||
completeLog = string.Concat(logString, "\n", stackTrace);
|
||||
|
||||
return completeLog;
|
||||
}
|
||||
return completeLog;
|
||||
}
|
||||
|
||||
// Credit: https://stackoverflow.com/a/19250516/2373034
|
||||
public int GetContentHashCode()
|
||||
{
|
||||
if( hashValue == HASH_NOT_CALCULATED )
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
hashValue = 17;
|
||||
hashValue = hashValue * 23 + ( logString == null ? 0 : logString.GetHashCode() );
|
||||
hashValue = hashValue * 23 + ( stackTrace == null ? 0 : stackTrace.GetHashCode() );
|
||||
}
|
||||
}
|
||||
// Credit: https://stackoverflow.com/a/19250516/2373034
|
||||
public int GetContentHashCode()
|
||||
{
|
||||
if (hashValue == HASH_NOT_CALCULATED)
|
||||
unchecked
|
||||
{
|
||||
hashValue = 17;
|
||||
hashValue = hashValue * 23 + (logString == null ? 0 : logString.GetHashCode());
|
||||
hashValue = hashValue * 23 + (stackTrace == null ? 0 : stackTrace.GetHashCode());
|
||||
}
|
||||
|
||||
return hashValue;
|
||||
}
|
||||
}
|
||||
return hashValue;
|
||||
}
|
||||
}
|
||||
|
||||
public struct QueuedDebugLogEntry
|
||||
{
|
||||
public readonly string logString;
|
||||
public readonly string stackTrace;
|
||||
public readonly LogType logType;
|
||||
public struct QueuedDebugLogEntry
|
||||
{
|
||||
public readonly string logString;
|
||||
public readonly string stackTrace;
|
||||
public readonly LogType logType;
|
||||
|
||||
public QueuedDebugLogEntry( string logString, string stackTrace, LogType logType )
|
||||
{
|
||||
this.logString = logString;
|
||||
this.stackTrace = stackTrace;
|
||||
this.logType = logType;
|
||||
}
|
||||
public QueuedDebugLogEntry(string logString, string stackTrace, LogType logType)
|
||||
{
|
||||
this.logString = logString;
|
||||
this.stackTrace = stackTrace;
|
||||
this.logType = logType;
|
||||
}
|
||||
|
||||
// Checks if logString or stackTrace contains the search term
|
||||
public bool MatchesSearchTerm( string searchTerm )
|
||||
{
|
||||
return ( logString != null && DebugLogConsole.caseInsensitiveComparer.IndexOf( logString, searchTerm, CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace ) >= 0 ) ||
|
||||
( stackTrace != null && DebugLogConsole.caseInsensitiveComparer.IndexOf( stackTrace, searchTerm, CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace ) >= 0 );
|
||||
}
|
||||
}
|
||||
// Checks if logString or stackTrace contains the search term
|
||||
public bool MatchesSearchTerm(string searchTerm)
|
||||
{
|
||||
return (logString != null && DebugLogConsole.caseInsensitiveComparer.IndexOf(logString, searchTerm,
|
||||
CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace) >= 0) ||
|
||||
(stackTrace != null && DebugLogConsole.caseInsensitiveComparer.IndexOf(stackTrace, searchTerm,
|
||||
CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace) >= 0);
|
||||
}
|
||||
}
|
||||
|
||||
public struct DebugLogEntryTimestamp
|
||||
{
|
||||
public readonly System.DateTime dateTime;
|
||||
public struct DebugLogEntryTimestamp
|
||||
{
|
||||
public readonly DateTime dateTime;
|
||||
#if !IDG_OMIT_ELAPSED_TIME
|
||||
public readonly float elapsedSeconds;
|
||||
public readonly float elapsedSeconds;
|
||||
#endif
|
||||
#if !IDG_OMIT_FRAMECOUNT
|
||||
public readonly int frameCount;
|
||||
public readonly int frameCount;
|
||||
#endif
|
||||
|
||||
#if !IDG_OMIT_ELAPSED_TIME && !IDG_OMIT_FRAMECOUNT
|
||||
public DebugLogEntryTimestamp( System.DateTime dateTime, float elapsedSeconds, int frameCount )
|
||||
public DebugLogEntryTimestamp(DateTime dateTime, float elapsedSeconds, int frameCount)
|
||||
#elif !IDG_OMIT_ELAPSED_TIME
|
||||
public DebugLogEntryTimestamp( System.DateTime dateTime, float elapsedSeconds )
|
||||
#elif !IDG_OMIT_FRAMECOUNT
|
||||
@@ -115,53 +118,54 @@ namespace IngameDebugConsole
|
||||
#else
|
||||
public DebugLogEntryTimestamp( System.DateTime dateTime )
|
||||
#endif
|
||||
{
|
||||
this.dateTime = dateTime;
|
||||
{
|
||||
this.dateTime = dateTime;
|
||||
#if !IDG_OMIT_ELAPSED_TIME
|
||||
this.elapsedSeconds = elapsedSeconds;
|
||||
this.elapsedSeconds = elapsedSeconds;
|
||||
#endif
|
||||
#if !IDG_OMIT_FRAMECOUNT
|
||||
this.frameCount = frameCount;
|
||||
this.frameCount = frameCount;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public void AppendTime( StringBuilder sb )
|
||||
{
|
||||
// Add DateTime in format: [HH:mm:ss]
|
||||
sb.Append( "[" );
|
||||
public void AppendTime(StringBuilder sb)
|
||||
{
|
||||
// Add DateTime in format: [HH:mm:ss]
|
||||
sb.Append("[");
|
||||
|
||||
int hour = dateTime.Hour;
|
||||
if( hour >= 10 )
|
||||
sb.Append( hour );
|
||||
else
|
||||
sb.Append( "0" ).Append( hour );
|
||||
var hour = dateTime.Hour;
|
||||
if (hour >= 10)
|
||||
sb.Append(hour);
|
||||
else
|
||||
sb.Append("0").Append(hour);
|
||||
|
||||
sb.Append( ":" );
|
||||
sb.Append(":");
|
||||
|
||||
int minute = dateTime.Minute;
|
||||
if( minute >= 10 )
|
||||
sb.Append( minute );
|
||||
else
|
||||
sb.Append( "0" ).Append( minute );
|
||||
var minute = dateTime.Minute;
|
||||
if (minute >= 10)
|
||||
sb.Append(minute);
|
||||
else
|
||||
sb.Append("0").Append(minute);
|
||||
|
||||
sb.Append( ":" );
|
||||
sb.Append(":");
|
||||
|
||||
int second = dateTime.Second;
|
||||
if( second >= 10 )
|
||||
sb.Append( second );
|
||||
else
|
||||
sb.Append( "0" ).Append( second );
|
||||
var second = dateTime.Second;
|
||||
if (second >= 10)
|
||||
sb.Append(second);
|
||||
else
|
||||
sb.Append("0").Append(second);
|
||||
|
||||
sb.Append( "]" );
|
||||
}
|
||||
sb.Append("]");
|
||||
}
|
||||
|
||||
public void AppendFullTimestamp( StringBuilder sb )
|
||||
{
|
||||
AppendTime( sb );
|
||||
public void AppendFullTimestamp(StringBuilder sb)
|
||||
{
|
||||
AppendTime(sb);
|
||||
|
||||
#if !IDG_OMIT_ELAPSED_TIME && !IDG_OMIT_FRAMECOUNT
|
||||
// Append elapsed seconds and frame count in format: [1.0s at #Frame]
|
||||
sb.Append( "[" ).Append( elapsedSeconds.ToString( "F1" ) ).Append( "s at " ).Append( "#" ).Append( frameCount ).Append( "]" );
|
||||
// Append elapsed seconds and frame count in format: [1.0s at #Frame]
|
||||
sb.Append("[").Append(elapsedSeconds.ToString("F1")).Append("s at ").Append("#").Append(frameCount)
|
||||
.Append("]");
|
||||
#elif !IDG_OMIT_ELAPSED_TIME
|
||||
// Append elapsed seconds in format: [1.0s]
|
||||
sb.Append( "[" ).Append( elapsedSeconds.ToString( "F1" ) ).Append( "s]" );
|
||||
@@ -169,19 +173,19 @@ namespace IngameDebugConsole
|
||||
// Append frame count in format: [#Frame]
|
||||
sb.Append( "[#" ).Append( frameCount ).Append( "]" );
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class DebugLogEntryContentEqualityComparer : EqualityComparer<DebugLogEntry>
|
||||
{
|
||||
public override bool Equals( DebugLogEntry x, DebugLogEntry y )
|
||||
{
|
||||
return x.logString == y.logString && x.stackTrace == y.stackTrace;
|
||||
}
|
||||
public class DebugLogEntryContentEqualityComparer : EqualityComparer<DebugLogEntry>
|
||||
{
|
||||
public override bool Equals(DebugLogEntry x, DebugLogEntry y)
|
||||
{
|
||||
return x.logString == y.logString && x.stackTrace == y.stackTrace;
|
||||
}
|
||||
|
||||
public override int GetHashCode( DebugLogEntry obj )
|
||||
{
|
||||
return obj.GetContentHashCode();
|
||||
}
|
||||
}
|
||||
public override int GetHashCode(DebugLogEntry obj)
|
||||
{
|
||||
return obj.GetContentHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user