-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebugLog.cs
More file actions
129 lines (105 loc) · 4.38 KB
/
Copy pathdebugLog.cs
File metadata and controls
129 lines (105 loc) · 4.38 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
debugLog.cs
Tony Monckton (c) 2019
*/
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace TM.Utils {
public class MessageLog {
public string name;
public string category;
public string key;
public string text;
public MessageLog() {
name = "";
category = "";
key = "";
text = "";
}
}
public class CategoryLog {
public string category;
public bool expanded;
public CategoryLog() {
category = "";
expanded = false;
}
}
public class debugLog
{
static debugLog _instance = null;
public static debugLog instance {
get {
if (_instance == null) {
_instance = new debugLog();
}
return _instance;
}
}
private debugLog() {}
// my vars
private System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
public Dictionary<string, MessageLog> messageLog = new Dictionary<string, MessageLog>();
public Dictionary<string, CategoryLog> categoryLog = new Dictionary<string, CategoryLog>();
public void Awake()
{
if (_instance != null) {
//Destroy(this.gameObject);
return;
}
_instance = this;
}
public CategoryLog getCategory( string _key) { return categoryLog[_key]; }
public void setCategory( CategoryLog _cat ) {
if (categoryLog[_cat.category] != null ) {
categoryLog[_cat.category].category = _cat.category;
categoryLog[_cat.category].expanded = _cat.expanded;
}
}
public void addCategory( CategoryLog _cat ) {
if ( categoryLog.ContainsKey(_cat.category) == false) {
categoryLog.Add( _cat.category, _cat );
}
}
public MessageLog getMessage ( string _key ) { return messageLog[_key]; }
public void setMessage( MessageLog _msg ) { }
public void beginTimer() {
stopwatch.Start();
}
public void endTimer( string _category, string _name ) {
object _message = stopwatch.ElapsedMilliseconds;
Log( _category, _name, _message);
}
public void Log( string _category, string _name, object _message) {
MessageLog message;
CategoryLog cat;
string key = _category + "_" + _name;
if (!categoryLog.ContainsKey(_category)) {
cat = new CategoryLog();
cat.category = _category;
cat.expanded = false;
categoryLog.Add(_category, cat);
}
if (!messageLog.ContainsKey(key)) {
message = new MessageLog();
message.name = _name;
message.category = _category;
message.key = key;
message.text = _message.ToString();
messageLog.Add(key, message);
} else
{
message = messageLog[key];
message.text = _message.ToString();
}
}
void OnDestroy() {
messageLog.Clear();
}
}
}