• Stars
    star
    445
  • Rank 98,085 (Top 2 %)
  • Language
    C#
  • License
    MIT License
  • Created over 6 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Unity Command Terminal: In-Game Console

Unity Command Terminal

A simple and highly performant in-game drop down Console.

gif

Command Terminal is based on an implementation by Jonathan Blow done in the Jai programming language.

Usage

Copy the contents from CommandTerminal to your Assets folder. Attach a Terminal Component to a game object. The console window can be toggled with a hotkey (default is backtick), and another hotkey can be used to toggle the full size window (default is shift+backtick).

Enter help in the console to view all available commands, use the up and down arrow keys to traverse the command history, and the tab key to autocomplete commands.

Registering Commands

There are 3 options to register commands to be used in the Command Terminal.

1. Using the RegisterCommand attribute:

The command method must be static (public or non-public).

[RegisterCommand(Help = "Adds 2 numbers", MinArgCount = 2, MaxArgCount = 2)]
static void CommandAdd(CommandArg[] args) {
    int a = args[0].Int;
    int b = args[1].Int;

    if (Terminal.IssuedError) return; // Error will be handled by Terminal

    int result = a + b;
    Terminal.Log("{0} + {1} = {2}", a, b, result);
}

MinArgCount and MaxArgCount allows the Command Interpreter to issue an error if arguments have been passed incorrectly, this way you can index the CommandArg array, knowing the array will have the correct size.

In this case the command name (add) will be inferred from the method name, you can override this by setting Name in RegisterCommand.

[RegisterCommand(Name = "MyAdd", Help = "Adds 2 numbers", MinArgCount = 2, MaxArgCount = 2)]

2. Using a FrontCommand method:

Here you still use the RegisterCommand attribute, but the arguments are handled in a separate method, prefixed with FrontCommand. This way, MaxArgCount and MinArgCount are automatically inferred.

This also allows you to keep the argument handling FrontCommand methods in another file, or even generate them procedurally during a pre-build.

[RegisterCommand(Help = "Adds 2 numbers")]
static void CommandAdd(int a, int b) {
    int result = a + b;
    Terminal.Log("{0} + {1} = {2}", a, b, result);
}

static void FrontCommandAdd(CommandArg[] args) {
    int a = args[0].Int;
    int b = args[1].Int;

    if (Terminal.IssuedError) return;

    CommandAdd(a, b);
}

3. Manually adding Commands:

RegisterCommand only works for static methods. If you want to use a non-static method, you may add the command manually.

Terminal.Shell.AddCommand("add", CommandAdd, 2, 2, "Adds 2 numbers");

More Repositories

1

UnityStyleGuide

For file structure, naming conventions and other things
HTML
237
star
2

raycaster

A bare metal raycaster, boots from a floppy image
Assembly
103
star
3

px

A tiny puzzle game framework
JavaScript
54
star
4

twoecs

C++ Entity Component Systems library
C++
23
star
5

autoyt

A tool for automating the editing and uploading process of YouTube music videos
Go
12
star
6

linguist256

Terminal version of Github Linguist
Python
10
star
7

vim-nebula

A simple and cozy vim color scheme
Vim Script
9
star
8

wincap.vim

Customize gvim.exe window color
C
7
star
9

UnityIniExtension

library for serializing object properties to .ini configuration files in unity
C#
6
star
10

editor2d

Tile based level editor for Unity
C#
5
star
11

miniasm

The miniasm language
C#
4
star
12

srwb

subreddit word bot
Python
4
star
13

edwin

A small GUI library for creating debug tools for Windows applications
C
3
star
14

pam

Process Activity Monitor
C#
2
star
15

ava-lang

Ava compiler and VM
F#
2
star
16

static_playerprefs

Alternative to Unity's PlayerPrefs module
C#
2
star
17

ava-vscode

Ava theme for vscode
Python
2
star
18

boolscript

The Boolscript Language
Python
2
star
19

liquidecs

A tiny Entity Component System library for Unity
C#
1
star
20

super_ini

The INI preprocessor
Python
1
star
21

neonray

Neon ray tracer
C++
1
star
22

bl_unity_exporter

Unity Exporter Add-on for Blender
Python
1
star
23

swatchmaker

Create swatches from a list of colors
Python
1
star
24

py.lang

document format for use in localizing text
Python
1
star
25

liquidconsole

Under construction
C#
1
star
26

nocraft

voxel rendering practice
C++
1
star
27

csbitset

C# bitset
C#
1
star