Documentation for the Unity C# Library
Loading...
Searching...
No Matches
LogDisplayer.cs
Go to the documentation of this file.
1using UnityEngine;
2using System.Collections;
3
5{
6 string currentLog;
7 Queue logQueue = new Queue();
8 float counter = 0f;
9
10 void Start()
11 {
12 }
13
14 private void Update()
15 {
16 if (logQueue.Count > 0)
17 {
18 counter += Time.deltaTime;
19
20 if (counter > 5.0f)
21 {
22 counter -= 5.0f;
23 logQueue.Dequeue();
24 RebuildLog();
25 }
26 }
27 }
28
29 void OnEnable()
30 {
31 Application.logMessageReceived += HandleLog;
32 }
33
34 void OnDisable()
35 {
36 Application.logMessageReceived -= HandleLog;
37 }
38
39 void HandleLog(string logString, string stackTrace, LogType type)
40 {
41 currentLog = logString;
42 string newString = "\n [" + type + "] : " + currentLog;
43
44 logQueue.Enqueue(newString);
45
46 if (type == LogType.Exception)
47 {
48 newString = "\n" + stackTrace;
49 logQueue.Enqueue(newString);
50 }
51
52 RebuildLog();
53 }
54
56 {
57 currentLog = string.Empty;
58
59 foreach (string log in logQueue)
60 {
61 currentLog += log;
62 }
63 }
64
65 void OnGUI()
66 {
67 GUIStyle labelStyle = new GUIStyle(GUI.skin.label);
68 labelStyle.normal.textColor = Color.red;
69 GUILayout.Label(currentLog, labelStyle);
70 }
71}
string currentLog
void RebuildLog()
void HandleLog(string logString, string stackTrace, LogType type)
void OnEnable()
void OnDisable()