Execute game commands via text input with a console-like system. Supports simple callbacks, advanced command registration with automatic argument parsing, async operations, and custom argument parsers. Built-in parsers handle primitives while extensible architecture allows custom types and subcommand groups for organized command hierarchies.
Install via Unity Package Manager
Add to Unity Package Manager
Paste this URL into Unity's Window › Package Manager › + › Add package from git URL,
or click Install.
git
https://www.pkglnk.dev/barionlp-command.git Install 0
Unity Compatibility
Unity 6 2023.2 2023.1 2022.3 LTS 2021.3 LTS 2020.3 LTS 2019.4 LTS
README
Rendered from GitHubCommand System
A system for calling funcions via text input (made for Unity, can be used outside)
Usage (Unity)
- install Command Sytem package (https://github.com/BarionLP/CommandSystem.git)
Run Commands
CommandManager.Execute("command");
Set Logger
CommandManager.SetLogger(new UnityDebugCommandLogger()); // print logs in the unity console
// Custom Logger
public class CustomLogger : ICommandLogger
{
public void Log(string message) => Debug.Log(message);
public void LogWarning(string message) => Debug.LogWarning(message);
public void LogError(string message) => Debug.LogError(message);
}
Simple Commands
CommandManager.Commands.Register(new SimpleCommand("test", ()->
{
// Do something
// Logging
CommandManager.Log();
CommandManager.LogWarning();
CommandManager.LogError();
}));
Advanced Commands
// register static methods with the Command attribute
// automatically generates syntax hints
CommandManager.Commands.Register<TestCommands>();
// register command "cmd" with the methods as subcommands (e.g. "cmd add 4 2")
CommandManager.Commands.RegisterGroup<TestCommands>("cmd");
public class TestCommands
{
[Command("add")] // automatically parses primitive arguments
public static void Add(int left, int right) => CommandManager.Log($"{left} + {right} is {left+right}");
[Command("wait")] // supports async
public static async Task Test(float seconds) => await Task.Delay((int)(seconds*1000));
[Command("give")] // other types require custom parsers (see below)
public static void GiveItem(Item item) => Player.Give(item);
}
Parsers
// has built in parsers for most primitives (float, int, long, short, ...) see `ArgumentParser.cs`
ArgumentParsers.Register<CustomType>(new CustomParser()); // register a custom parser
ArgumentParsers.Register<CustomEnum>(new EnumArgumentParser<CustomEnum>()); // generates an enum parser (parses by name)
public class CustomParser : IArgumentParser<CustomType>
{
public CustomType Parse(ReadOnlySpan<char> raw) => // however you want, e.g. from a registry (`null` if fails)
public IEnumerable<string> GetSuggestions() => Enumerable.Empty<string>(); // or all possible values
}
Versions 1
- v0.3.1 current
Dependencies 0
No dependencies.
Changelog 0 releases
No changelog entries yet. Run the admin Changelog & Version Scanner to pull from the repository's CHANGELOG.md.
README Markdown
Copy this to your project's README.md
## Installation
Add **Ametrin Command System** 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/barionlp-command.git
```
[](https://www.pkglnk.dev/pkg/barionlp-command)Embed badge README snippet
Markdown
[](https://www.pkglnk.dev/pkg/barionlp-command) HTML
<a href="https://www.pkglnk.dev/pkg/barionlp-command"><img src="https://www.pkglnk.dev/badge/barionlp-command.svg" alt="pkglnk installs"></a> URL
https://www.pkglnk.dev/badge/barionlp-command.svg Comments
No comments yet. Be the first!


Sign in to join the conversation
Sign In