Skip to content

Commit e05398d

Browse files
committed
Updated readme
1 parent 0fec5f3 commit e05398d

File tree

1 file changed

+41
-22
lines changed

1 file changed

+41
-22
lines changed

README.md

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,49 @@
11
# unity-debug-overlay
2-
A fast and garbage free debug overlay for Unity
2+
A fast and (almost) garbage free debug overlay for Unity. The projects contains two primary components: a debug overlay
3+
and a console.
4+
5+
# Debug overlay
6+
The debug overlay, useful for displaying text and graphs that update every frame.
7+
Like this: ![Pretty picture](https://user-images.githubusercontent.com/4175246/28583020-e34a3a12-7167-11e7-8871-7199f410aa8d.gif)
8+
9+
This can be done with some level of convenience using this code:
10+
11+
```c#
12+
// FPS in top left corner
13+
DebugOverlay.Write(1, 0, "FPS:{0,6:###.##}", 1.0f / Time.deltaTime);
14+
15+
// Small graph of FPS below
16+
fpsHistory[Time.frameCount % fpsHistory.Length] = 1.0f / Time.deltaTime;
17+
DebugOverlay.DrawGraph(1, 1, 9, 1.5f, fpsHistory, Time.frameCount % fpsHistory.Length, Color.green);
18+
```
19+
20+
Even though it involves string formatting, not garbage will be generated.
21+
22+
# Console
23+
The console is useful for checking logs / output while ingame and also for easily registrering commands
24+
that can be used to tweak the game behaviour or turn on/off debugging aspects.
325

426
You can write stuff like
527

628
```c#
7-
DebugOverlay.Write(2, 2, "Hello, {0,-5} world!", Time.frameCount%100<50 ? "Happy" : "Evil");
8-
DebugOverlay.Write("FrameNo: {0,7}", Time.frameCount);
9-
DebugOverlay.Write("Time: {0,7:0000.00}", Time.time);
10-
DebugOverlay.Write("FPS: {0,7:###.##}", 1.0f / Time.deltaTime);
11-
DebugOverlay.Write("MonoHeap:{0,7} kb", (int)(UnityEngine.Profiling.Profiler.GetMonoUsedSizeLong() / 1024));
12-
DebugOverlay.DrawRect(20, 5.2f, 1.0f/Time.deltaTime*0.1f, 0.6f, Color.green);
13-
DebugOverlay.Write("PlayerPos: {0,6:000.0} {1,6:000.0} {2,6:000.0}",
14-
transform.position.x,
15-
transform.position.y,
16-
transform.position.z);
17-
18-
/// Graphing
19-
System.Array.Copy(fpsArray, 1, fpsArray, 0, fpsArray.Length - 1);
20-
fpsArray[fpsArray.Length - 1] = 1.0f / Time.deltaTime;
21-
DebugOverlay.DrawHist(20, 10, 20, 3, fpsArray, Color.blue, 120.0f);
22-
23-
System.Array.Copy(moveArray, 1, moveArray, 0, moveArray.Length - 1);
24-
moveArray[moveArray.Length - 1] = transform.parent.position.y;
25-
DebugOverlay.DrawHist(20, 15, 20, 3, moveArray, Color.red, 4.0f);
29+
30+
// Register quit command
31+
Game.console.AddCommand("quit", CmdQuit, "Quit game");
32+
33+
/* ... */
34+
35+
void CmdQuit(string[] args)
36+
{
37+
Game.console.
38+
Application.Quit();
39+
}
40+
41+
42+
2643
```
2744

28-
and it will look like
45+
and it will look like this
46+
47+
![Pretty picture](https://user-images.githubusercontent.com/4175246/28582984-d215e5f2-7167-11e7-99ff-e96b2981b9bb.gif)
48+
2949

30-
![Pretty picture](https://user-images.githubusercontent.com/4175246/27818480-0fcb0176-6096-11e7-9962-4371342402f2.png)

0 commit comments

Comments
 (0)