DebugLogEntry.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using UnityEngine;
  2. // Container for a simple debug entry
  3. namespace IngameDebugConsole
  4. {
  5. public class DebugLogEntry : System.IEquatable<DebugLogEntry>
  6. {
  7. private const int HASH_NOT_CALCULATED = -623218;
  8. public string logString;
  9. public string stackTrace;
  10. private string completeLog = null;
  11. // Sprite to show with this entry
  12. public Sprite logTypeSpriteRepresentation;
  13. // Collapsed count
  14. public int count;
  15. private int hashValue = HASH_NOT_CALCULATED;
  16. public DebugLogEntry( string logString, string stackTrace, Sprite sprite )
  17. {
  18. this.logString = logString;
  19. this.stackTrace = stackTrace;
  20. logTypeSpriteRepresentation = sprite;
  21. count = 1;
  22. }
  23. // Check if two entries have the same origin
  24. public bool Equals( DebugLogEntry other )
  25. {
  26. return this.logString == other.logString && this.stackTrace == other.stackTrace;
  27. }
  28. // Return a string containing complete information about this debug entry
  29. public override string ToString()
  30. {
  31. if( completeLog == null )
  32. completeLog = string.Concat( logString, "\n", stackTrace );
  33. return completeLog;
  34. }
  35. // Credit: https://stackoverflow.com/a/19250516/2373034
  36. public override int GetHashCode()
  37. {
  38. if( hashValue == HASH_NOT_CALCULATED )
  39. {
  40. unchecked
  41. {
  42. hashValue = 17;
  43. hashValue = hashValue * 23 + logString == null ? 0 : logString.GetHashCode();
  44. hashValue = hashValue * 23 + stackTrace == null ? 0 : stackTrace.GetHashCode();
  45. }
  46. }
  47. return hashValue;
  48. }
  49. }
  50. public struct QueuedDebugLogEntry
  51. {
  52. public readonly string logString;
  53. public readonly string stackTrace;
  54. public readonly LogType logType;
  55. public QueuedDebugLogEntry( string logString, string stackTrace, LogType logType )
  56. {
  57. this.logString = logString;
  58. this.stackTrace = stackTrace;
  59. this.logType = logType;
  60. }
  61. }
  62. }