Author: Jeremy Hollingsworth (jeremyace)
- Simon Waite (opless) 22 Feb 2006
NOTE: An updated DebugConsole providing command binding, watch vars and some other goodies is available for free here: http://www.ennanzus-interactive.com/developer/DebugConsole/
This script will create a scrolling debug console. Allows you to set one of three colors (normal, warning, error) to each line to get more feedback and is mouse draggable at runtime.
Drop the DebugConsole script into your Standard Assets folder (This is a requirement). It is now fully usable.
If you want to change the default settings (like colors, or change the GUIText object), then create an empty GameObject and drag this script onto it from the standard assets folder. You now have access to all of the default settings in the inspector. The settings are explained below.
- Debug GUI : Drag the guiText you created here if you wish to override the default.
- defaultGuiPosition : A vector for the starting position of the first line of output. If you provide your own GUIText then it's position overrides this property.
- defaultGuiScale : A vector for the scale of the individual lines. Again, this is overridden if you provide your own GUIText.
- The three colors : are for normal, warning, and error. Set to whatever you like or leave alone.
- Max messages : How many message lines we will put on the screen at once.
- Line Spacing : A float for how far down we will move each new line.
- Draggable : True means you can drag the output around with the mouse at runtime, false means position is locked from mouse input. To drag output at runtime, click once on the uppermost output line to connect it to the mouse, then move to where you want the output displayed and click the mouse again to release it.
- Visible : The default setting for visibility of the debug output. If set to false (unchecked), you can send data but it wont show until you tell it to, if set to true (checked) it will show all debug output until you tell it not to.
- PixelCorrect : If set to true and LineSpacing to be on-screen pixels or not, very much like the GUIText property of the same name. Default: false LineSpacing will be in screen coordinates (0.0 - 1.0)
Using the DebugConsole script from your scripts:
To call the DebugConsole script from your scripts, just type:
Replace someFunction() with any of the following:
Log (string message, string color)
- Adds a message to the list. The color is a string either "normal", "warning" or "error". The color argument is optional and if omitted, the color will default to "normal".
- Clears all of the messages from the list and the screen.
To toggle the visibility use:
IsOpen (true, false)
- The property to set the visiblility of the debug output. This property _not_ clear the message list, just hides it. You need to use the Clear() method to clear the list.
To toggle the mouse drag functionality use:
isDraggable (true, false)
So for a simple example, to add hello world in warning color (yellow), we type: DebugConsole.Log("hello world", "warning");
To hide the output we type: DebugConsole.IsOpen = false;