15th November 2011
Link with 20 notes
DebugConsole.cs
DebugConsole.cs has been really useful to me. Especially when I’ve been trying to debug iPhone or standalone builds of Unity projects.
When I first added the DebugConsole to my project I didn’t understand a lot of the magic it contained. I’m pretty sure it was my first introduction to C# delegates. Since then I’ve leveled up a few times and add a ton of stuff to the DebugConsole script.
I’m sharing my modifications to the DebugConsole, because learning how it worked was so helpful to me.
Here are a couple of the changes that I’ve made, you’ll have to scour the source and learn some stuff to discover all of it.
- Generic WatchVar. This should let people watch any object that has a ToString() method.
- Added an FPS counter. This is based off one of the scripts in UnifyCommunity.com
- Removed GUILayout stuff. This should let it work better on mobile devices (haven’t tried in a while though).
- Console Command delegate returns an object which will be printed to the console, so the functions can return info to the console.
- Hitting
<enter> now submits the command line if it has focus.
- Added a toggle key that shows/hides the console (default is “`”, same as the Quake console).
- Pressing up arrow goes back through command history (like a Unix prompt).
- Log functions return the object that they were sent. This lets you double up logging ( Debug.Log(DebugConsole.Log(“blah”)); ) This is useful because in the editor you can continue to get log messages that can be double clicked on to take you into the source file.
Tagged: CSharpDebugUnity3Dgamedev