Advertisement
Guest User

Untitled

a guest
Jul 21st, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. namespace EpicHax
  6. {
  7. public class Console : MonoBehaviour
  8. {
  9. public void OnEnable()
  10. {
  11. Application.RegisterLogCallback(new Application.LogCallback(this.HandleLog));
  12. }
  13.  
  14. public void OnDisable()
  15. {
  16. Application.RegisterLogCallback(null);
  17. }
  18.  
  19. public void Update()
  20. {
  21. if (Input.GetKeyDown(KeyCode.KeypadMinus))
  22. {
  23. Statics.consoleEnabled = !Statics.consoleEnabled;
  24. }
  25. this.show = Statics.consoleEnabled;
  26. }
  27.  
  28. public void OnGUI()
  29. {
  30. if (!this.show)
  31. {
  32. return;
  33. }
  34. this.windowRect = GUILayout.Window(123456, this.windowRect, new GUI.WindowFunction(this.ConsoleWindow), "Console", new GUILayoutOption[0]);
  35. }
  36.  
  37. public void ConsoleWindow(int windowID)
  38. {
  39. this.scrollPosition = GUILayout.BeginScrollView(this.scrollPosition, new GUILayoutOption[0]);
  40. for (int i = 0; i < this.logs.Count; i++)
  41. {
  42. Console.Log log = this.logs[i];
  43. if (!this.collapse || i <= 0 || !(log.message == this.logs[i - 1].message))
  44. {
  45. GUI.contentColor = Console.logTypeColors[log.type];
  46. GUILayout.Label(log.message, new GUILayoutOption[0]);
  47. }
  48. }
  49. GUILayout.EndScrollView();
  50. GUI.contentColor = Color.white;
  51. GUILayout.BeginHorizontal(new GUILayoutOption[0]);
  52. if (GUILayout.Button(this.clearLabel, new GUILayoutOption[0]))
  53. {
  54. this.logs.Clear();
  55. }
  56. this.collapse = GUILayout.Toggle(this.collapse, this.collapseLabel, new GUILayoutOption[]
  57. {
  58. GUILayout.ExpandWidth(false)
  59. });
  60. GUILayout.EndHorizontal();
  61. GUI.DragWindow(this.titleBarRect);
  62. }
  63.  
  64. public void HandleLog(string message, string stackTrace, LogType type)
  65. {
  66. this.logs.Add(new Console.Log
  67. {
  68. message = message,
  69. stackTrace = stackTrace,
  70. type = type
  71. });
  72. }
  73.  
  74. public Console()
  75. {
  76. }
  77.  
  78. static Console()
  79. {
  80. }
  81.  
  82. public KeyCode toggleKey = KeyCode.BackQuote;
  83.  
  84. public List<Console.Log> logs = new List<Console.Log>();
  85.  
  86. public Vector2 scrollPosition;
  87.  
  88. public bool show;
  89.  
  90. public bool collapse;
  91.  
  92. public static readonly Dictionary<LogType, Color> logTypeColors = new Dictionary<LogType, Color>
  93. {
  94. {
  95. LogType.Assert,
  96. Color.green
  97. },
  98. {
  99. LogType.Error,
  100. Color.magenta
  101. },
  102. {
  103. LogType.Exception,
  104. Color.red
  105. },
  106. {
  107. LogType.Log,
  108. Color.white
  109. },
  110. {
  111. LogType.Warning,
  112. Color.yellow
  113. }
  114. };
  115.  
  116. public const int margin = 20;
  117.  
  118. public Rect windowRect = new Rect(20f, 20f, (float)(Screen.width - 80), (float)(Screen.height - 80));
  119.  
  120. public Rect titleBarRect = new Rect(0f, 0f, 10000f, 20f);
  121.  
  122. public GUIContent clearLabel = new GUIContent("Clear", "Clear the contents of the console.");
  123.  
  124. public GUIContent collapseLabel = new GUIContent("Collapse", "Hide repeated messages.");
  125.  
  126. public struct Log
  127. {
  128. public string message;
  129.  
  130. public string stackTrace;
  131.  
  132. public LogType type;
  133. }
  134. }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement