// People should be able to see and report errors to the developer very easily.
//
// Unity's Developer Console only works in development builds and it only shows
// errors. This class provides a console that works in all builds and also shows
// log and warnings in development builds.
//
// Note: we don't include the stack trace, because that can also be grabbed from
// the log files if needed.
//
// Note: there is no 'hide' button because we DO want people to see those errors
// and report them back to us.
//
// Note: normal Debug.Log messages can be shown by building in Debug/Development
// mode.
usingUnityEngine;
usingSystem.Collections.Generic;
namespaceMirror
{
structLogEntry
{
publicstringmessage;
publicLogTypetype;
publicLogEntry(stringmessage,LogTypetype)
{
this.message=message;
this.type=type;
}
}
publicclassGUIConsole:MonoBehaviour
{
publicintheight=80;
publicintoffsetY=40;
// only keep the recent 'n' entries. otherwise memory would grow forever
// and drawing would get slower and slower.
publicintmaxLogCount=50;
// Unity Editor has the Console window, we don't need to show it there.
// unless for testing, so keep it as option.
publicboolshowInEditor=false;
// log as queue so we can remove the first entry easily
readonlyQueue<LogEntry>log=newQueue<LogEntry>();
// hotkey to show/hide at runtime for easier debugging
// (sometimes we need to temporarily hide/show it)
// Default is BackQuote, because F keys are already assigned in browsers
[Tooltip("Hotkey to show/hide the console at runtime\nBack Quote is usually on the left above Tab\nChange with caution - F keys are generally already taken in Browsers")]
publicKeyCodehotKey=KeyCode.BackQuote;
// GUI
boolvisible;
Vector2scroll=Vector2.zero;
// only show at runtime, or if showInEditor is enabled
boolshow=>!Application.isEditor||showInEditor;
voidAwake()
{
// only show at runtime, or if showInEditor is enabled
if(show)
Application.logMessageReceived+=OnLog;
}
// OnLog logs everything, even Debug.Log messages in release builds
// => this makes a lot of things easier. e.g. addon initialization logs.
// => it's really better to have than not to have those