Skip to content

Repository files navigation

UnityConsole

A Unity Runtime Console using UI Toolkit

Usage

Add Messages

ConsoleManager.AddMessage("message");ConsoleManager.AddMessage("<color=yellow>message</color>");// rich text support ConsoleManager.AddWarningMessage("warning");ConsoleManager.AddErrorMessage("error");

Hide and Show

ConsoleManager.Hide()/ConsoleManager.Show()
The ConsoleToggle component handles hiding and showing the console
You can listen to ConsoleManager.OnShow and ConsoleManager.OnHide

Input Handlers

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 =>{}));

Custom Handlers

// 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}}

Recommendation

If you want to run commands from this console consider using https://github.com/BarionLP/CommandSystem with https://github.com/BarionLP/UnityConsoleCommandIntegration

About

A Unity Runtime Console using UI Toolkit

Topics

Resources

Stars

17 stars

Watchers

1 watching

Forks

Releases

Contributors

Languages