Unclaimed Package Is this your package? Claim it to unlock full analytics and manage your listing.
Claim This Package

Install via UPM

Add to Unity Package Manager using this URL

https://www.pkglnk.dev/unity-console.git

README Markdown

Copy this to your project's README.md

Style
Preview
pkglnk installs badge
## Installation

Add **Unity Runtime Console** to your Unity project via Package Manager:

1. Open **Window > Package Manager**
2. Click **+** > **Add package from git URL**
3. Enter:
```
https://www.pkglnk.dev/unity-console.git
```

[![pkglnk](https://www.pkglnk.dev/badge/unity-console.svg?style=pkglnk)](https://www.pkglnk.dev/pkg/unity-console)

README

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 handler
ConsoleManager.OverrideDefaultHandler(new ConsoleMessageHandler(input => {}));
// registering other handlers
char prefix = '/'; // inputs staring with this prefix are handed to this handler
ConsoleManager.RegisterHandler(prefix, new ConsoleMessageHandler(input => {}));

Custom Handlers

// implement IConsoleHandler
public sealed class CustomHandler : IConsoleHandler
{
    // whether the prefix should be removed before calling Handle
    public bool PassPrefix => false;
    
    public void Handle(ReadOnlySpan<char> input)
    {
        // whatever you want
    }

    // optional
    public string GetHint(ReadOnlySpan<char> input)
    {
        // displays a hint above the text input, can be empty
        // runs whenever the input changes, so be performance aware 
    }

    // optional
    public string GetAutoCompleted(ReadOnlySpan<char> input)
    {
        // called when tab is pressed
        // return the 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

Comments

No comments yet. Be the first!