Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/popcron/command-runner
A utility that allows for commands that can run in play and edit mode.
https://github.com/popcron/command-runner
Last synced: 21 days ago
JSON representation
A utility that allows for commands that can run in play and edit mode.
- Host: GitHub
- URL: https://github.com/popcron/command-runner
- Owner: popcron
- License: mit
- Created: 2022-07-24T16:01:37.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-14T00:22:24.000Z (about 1 year ago)
- Last Synced: 2023-10-15T14:50:08.239Z (about 1 year ago)
- Language: C#
- Size: 163 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Command Runner
A library that gives you the tools to parse user text to run commands!
### Dependencies and Installation
1. [UniTask](https://github.com/Cysharp/UniTask) and [TypeCache](https://github.com/popcron-games/com.popcron-games.typecache) are dependencies, make sure these are installed
1. Add this url to your packages manifest
```json
https://github.com/popcron/command-runner.git
```
2. Import the in game console and command loader samples into your project:
![image](https://user-images.githubusercontent.com/23342532/193724912-9387fc29-6415-42fb-838d-d40682175d58.png)*more information about this is in the [In game console](#in-game-console) section*
3. Drag and drop the `In Game Console` prefab into your scene
4. Done# Examples
### Adding a specific method as a command
```cs
ICommand command = new MethodCommand("yo", DoSomething);
Library.Singleton.Add(command);private void DoSomething()
{
}
```
### Adding a static method with an attribute
```cs
[Command("yo")]
private static void DoSomething()
{}
```### Run a command in code
```cs
await CommandRunner.Singleton.RunAsync("yo");
```### In game console (from the samples)
Some basic features:
1. Toggle it open using the `~` key (the key under `esc`).
2. Can select previous commands using the up arrow key
3. Shows the Debug.Log output from the command### Enumerate through and retrieve all commands
```cs
foreach (IBaseCommand prefab in Library.Singleton.Prefabs)
{
Debug.Log(prefab.Path);
if (prefab is IDescription desc)
{
Debug.LogFormat(" {0}", desc.Description);
}
}ICommand command = Library.Singleton.GetPrefab("ls commands");
```
### Create a brand new command runner
```cs
IParser parser = new ClassicParser();
ILibrary library = new Library(CommandFinder.FindAllCommands());
ICommandRunner runner = new CommandRunner(library, parser);ICommand customCommand = new MethodCommand("hey", () => Debug.Log("hello world"));
library.Add(customCommand);runner.Run("hey");
```