-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDebugMessages.cs
More file actions
139 lines (127 loc) · 4.78 KB
/
Copy pathDebugMessages.cs
File metadata and controls
139 lines (127 loc) · 4.78 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
130
131
132
133
134
135
136
137
138
139
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace PersistentTrails
{
public class DebugMessages// : MonoBehaviour
{
public bool debugMode = true;
private List<debugLine> outputLines = new List<debugLine>();
private float nextPostDuration = 5f;
public Rect screenPosition = new Rect(500f, 500f, 300f, 100f);
public float lineSpacing = 25f;
//public string debugMessageOutput = "both";
public enum OutputMode
{
screen,
log,
both,
none,
}
OutputMode outputMode = OutputMode.log;
public float postToScreenDuration = 5f;
public DebugMessages()
{
}
public DebugMessages(bool _debugMode, OutputMode _outputMode, float _postToScreenDuration)
{
debugMode = _debugMode;
outputMode = _outputMode;
postToScreenDuration = _postToScreenDuration;
}
public void debugMessage(string input) // fully automatic mode, posts to screen or or log depending on general setting
{
if (debugMode)
{
switch (outputMode)
{
case OutputMode.both:
debugMessage(input, true, postToScreenDuration);
break;
case OutputMode.log:
debugMessage(input, true, 0f);
break;
case OutputMode.screen:
debugMessage(input, false, postToScreenDuration);
break;
}
}
}
public void debugMessage(string input, bool postToLog, float postToScreenDuration) // fully manual mode, post to screen or log depending on parameters
{
if (debugMode)
{
PostMessage(input, postToLog, postToScreenDuration);
}
}
public void debugMessage(string input, float postToScreenDuration) // semi-manual mode: posts to screen regardless of general setting, and to log, depending on general setting
{
if (debugMode)
{
switch (outputMode)
{
case OutputMode.both:
debugMessage(input, true, postToScreenDuration);
break;
case OutputMode.log:
debugMessage(input, true, postToScreenDuration);
break;
case OutputMode.screen:
debugMessage(input, false, postToScreenDuration);
break;
}
}
}
public void PostMessage(string input, bool postToLog, float postToScreenDuration) // Posts uninstantiated, so it doesn't care about debugMode.
{
if (postToLog)
{
Debug.Log(input);
}
if (postToScreenDuration > 0f) // will only work in the flight scene, gives an error in other places.
{
outputLines.Add(new debugLine(input, postToScreenDuration));
//nextPostDuration = postToScreenDuration;
}
}
public void OnGUI()
{
if (outputLines.Count > 0)
{
for (int i = 0; i < outputLines.Count; i++)
{
GUI.Label(new Rect(screenPosition.x, screenPosition.y + lineSpacing * i, screenPosition.width, screenPosition.height), outputLines[i].text);
outputLines[i].delay -= Time.deltaTime;
if (outputLines[i].delay <= 0f)
{
outputLines.RemoveAt(i);
i--;
}
}
}
}
public static void Post(string input, bool postToLog, float postToScreenDuration) // Posts uninstantiated, so it doesn't care about debugMode.
{
if (postToLog)
{
Debug.Log(input);
}
if (postToScreenDuration > 0f && HighLogic.LoadedSceneIsFlight) // will only work in the flight scene, gives an error in other places.
{
ScreenMessages.PostScreenMessage(new ScreenMessage(input, postToScreenDuration, ScreenMessageStyle.UPPER_RIGHT));
}
}
}
public class debugLine
{
public string text;
public float delay;
public debugLine(string _text, float _delay)
{
text = _text;
delay = _delay;
}
}
}