Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/barionlp/unityconsole
A Unity Runtime Console using UI Toolkit
https://github.com/barionlp/unityconsole
unity
Last synced: 5 days ago
JSON representation
A Unity Runtime Console using UI Toolkit
- Host: GitHub
- URL: https://github.com/barionlp/unityconsole
- Owner: BarionLP
- License: mit
- Created: 2023-06-23T14:18:33.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-10T13:59:29.000Z (5 months ago)
- Last Synced: 2024-06-11T12:47:27.679Z (5 months ago)
- Topics: unity
- Language: C#
- Homepage:
- Size: 125 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# UnityConsole
A Unity Runtime Console using UI Toolkit## Usage
- requires Unity UI package (UI Toolkit)
- new input system recommended
- (optional) install [UpmGitExtension](https://github.com/mob-sakai/UpmGitExtension) package (https://github.com/mob-sakai/UpmGitExtension.git)
- install Unity Console package https://github.com/BarionLP/UnityConsole.git
- add the ConsolePrefab to your scene### Add Messages
```csharp
ConsoleManager.AddMessage("message");
ConsoleManager.AddMessage("message"); //rich text
ConsoleManager.AddWarningMessage("warning"); //yellow
ConsoleManager.AddErrorMessage("error"); //red
```
### Hide and Show
`ConsoleManager.Hide()`/`ConsoleManager.Show()`
The `ConsoleToggle` component handles hiding and showing the console automatically
You can listen to `ConsoleManager.OnShow` and `ConsoleManager.OnHide`### Input Handlers
by default the console just prints input messages
```csharp
// override the default handler
ConsoleManager.OverrideDefaultHandler(new ConsoleMessageHandler(input => {}));
//registering handlers
char prefix = '/'; //inputs staring with this prefix are handed to this handler
ConsoleManager.RegisterHandler(prefix, new ConsoleMessageHandler(input => {}));
```#### Custom Handlers
```csharp
//implement IConsoleHandler
public sealed class CustomHandler : IConsoleHandler {
//whether the prefix should be removed before calling
public bool PassPrefix => false;
public void Handle(ReadOnlySpan input){
//whatever you want
}//optional
public string GetHint(ReadOnlySpan input){
// displays a hint above the text input, can be empty
// runs whenever the input changes, so be performace aware
}//optional
public string GetAutoCompleted(ReadOnlySpan input){
// called when tab is pressed
// return the entire completed string or empty
}
}
```## Tipps
If you want to run commands from this console consider using https://github.com/BarionLP/CommandSystem with https://github.com/BarionLP/UnityConsoleCommandIntegration