A Unity Runtime Console using UI Toolkit
- requires Unity UI package (UI Toolkit)
- new input system recommended
- install Unity Console package https://github.com/BarionLP/UnityConsole.git
- add the ConsolePrefab to your scene
ConsoleManager.AddMessage("message");ConsoleManager.AddMessage("<color=yellow>message</color>");// rich text support ConsoleManager.AddWarningMessage("warning");ConsoleManager.AddErrorMessage("error");ConsoleManager.Hide()/ConsoleManager.Show()
The ConsoleToggle component handles hiding and showing the console
You can listen to ConsoleManager.OnShow and ConsoleManager.OnHide
by default the console just prints input messages
// override the default handlerConsoleManager.OverrideDefaultHandler(newConsoleMessageHandler(input =>{}));// registering other handlerscharprefix='/';// inputs staring with this prefix are handed to this handlerConsoleManager.RegisterHandler(prefix,newConsoleMessageHandler(input =>{}));// implement IConsoleHandlerpublicsealedclassCustomHandler:IConsoleHandler{// whether the prefix should be removed before calling HandlepublicboolPassPrefix=>false;publicvoidHandle(ReadOnlySpan<char>input){// whatever you want}// optionalpublicstringGetHint(ReadOnlySpan<char>input){// displays a hint above the text input, can be empty// runs whenever the input changes, so be performance aware }// optionalpublicstringGetAutoCompleted(ReadOnlySpan<char>input){// called when tab is pressed// return the completed string or empty}}If you want to run commands from this console consider using https://github.com/BarionLP/CommandSystem with https://github.com/BarionLP/UnityConsoleCommandIntegration