-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogDisplay.cs
More file actions
67 lines (59 loc) · 1.73 KB
/
Copy pathLogDisplay.cs
File metadata and controls
67 lines (59 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using UnityEngine;
using System.Collections;
public class LogDisplay : MonoBehaviour {
public bool isOpen = true;
public int FontSize = 24;
private string myLog = "";
private int btnSize = 30;
private GUIStyle btnStyle = null;
private GUIStyle labelStyle = null;
void OnEnable () {
Application.logMessageReceived += newLog;
}
void OnDisable () {
// Remove callback when object goes out of scope
Application.logMessageReceived -= newLog;
}
void InitGUI() {
if (btnStyle == null) {
int w = Screen.width, h = Screen.height;
btnStyle = new GUIStyle (GUI.skin.button);
btnStyle.fontSize = btnSize / 2;
}
if (labelStyle == null) {
labelStyle = new GUIStyle ();
labelStyle.alignment = TextAnchor.UpperLeft;
labelStyle.fontSize = FontSize;
labelStyle.normal.textColor = new Color (0.7f, 0.7f, 0.7f, 1.0f);
}
}
void OnGUI () {
InitGUI();
int w = Screen.width, h = Screen.height;
if (isOpen) {
if (GUI.Button(new Rect(10, 10, btnSize, btnSize), "x", btnStyle)) {
isOpen = false;
}
if (GUI.Button(new Rect(20 + btnSize , 10, btnSize, btnSize), "<", btnStyle)) {
FontSize -= 4;
labelStyle.fontSize = FontSize;
}
if (GUI.Button(new Rect(30 + btnSize * 2, 10, btnSize, btnSize), ">", btnStyle)) {
FontSize += 4;
labelStyle.fontSize = FontSize;
}
GUI.TextArea(new Rect(10, 10 + btnSize, Screen.width - 20, Screen.height - 20 - btnSize), myLog, labelStyle);
} else {
if (GUI.Button(new Rect(10, 10, btnSize, btnSize), "o", btnStyle)) {
isOpen = true;
}
}
}
public void newLog(string logString, string stackTrace, LogType type) {
myLog = logString + "\n" + myLog;
if (myLog.Length > 512) {
// if myLog is too long, cut it.
myLog = myLog.Substring(0, 374);
}
}
}