A lightweight, in-game developer console for Unity
A lightweight, in-game developer console for Unity
Quickly add new commands by marking a method with [Command]
:
[Command("cube")]
public static void CreateCube (Vector3 pos, float scale)
{
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.position = pos;
cube.transform.localScale = Vector3.one * scale;
}
// $ cube (1 2 3) 2
// Creates a cube at (1, 2, 3) with scale 2.0f
Parsing support for all basic C# types, IEnumerable
, List
, Dictionary
, and many more.
Fully customizable GetOpt
command syntax and automatic help text generation:
[Command("showcase", Description = "Showcases the flexibility of the command parser.")]
public static void CustomCommand(
[Positional(Description = "The first positional", Meta = "FOO")] Vector3 posOne,
[Positional(Description = "The second positional", Max = 4, Meta = "BAR", Optional = true)] IEnumerable posTwo,
[Switch('a', LongName = "flag", Description = "A flag")] bool flag,
[Switch('b', LongName = "switch", Description = "A switch", Meta = "STR")] string @switch)
{
// Command implementation
}
// Automatically generated help text:
// $ help showcase
// showcase: Showcases the flexibility of the command parser
//
// usage: showcase FOO [BAR] [-a] [-b STR]
// Format:
// FOO Vector3 (x y z)
// BAR IEnumerable [foo bar ...]
// STR string
//
// Mandatory Parameters:
// FOO The first positional
//
// Optional Parameters:
// BAR The second positional
// Can have at most 4 elements
// -a, --flag A flag
// -b, --switch A switch
Seamless parsing support for nested generic types, such as List
.>
Define parsers for custom types by extending the ParameterParser
.
Add custom widgets, images, and media by extending the ConsoleEntry
class.
Implement custom command line parsing through the IConsoleCommand
interface.
[Command("cmd")]
public class MyCommand : IConsoleCommand
{
public void Invoke(string data)
{
// Parse command line input passed to this command
}
}
ls
and pwd
.
A detailed documentation of all of these features and more over at the wiki!
2020.2
or greater3.0.1
or greater installed in your project. Comes built-in with Unity 2020.2
or greater..unitypackage
to your machine..unitypackage
by dragging and dropping it onto the Unity window or by going to Assets > Import Package > Custom Package... and selecting the package.Run:
~/MyProject $ openupm add com.cronyx.console
from within your project directory.
Add package from tarball...
Add package from git...
https://github.com/cronyxllc/DeveloperConsole.git#upm
for the URL when prompted.By default, you can open the in-game console by pressing the backquote key (`
) (or tilde, ~
, on QWERTY keyboards). This will open the console UI and allow you to start entering commands. For your first command, try printing the working directory:
~ $ pwd
C:\Users\MyUser\AppData\LocalLow\DefaultCompany\DeveloperConsole
~ $ █
Just like in a Bash console, past inputs can be cycled through using the up and down arrow keys. For a list of all commands that can be called, enter $ help
.
To customize the console's settings, go to Window > DeveloperConsole > Settings. This will create a ConsoleSettings
asset in your projects directory. Hover over any of the settings to get a description of what that feature does. For a more detailed description of the console's settings, see the settings documentation.
The DeveloperConsole
package was created with the intention that you would extend its functionality by creating console commands specific to your own project. Creating a console command can be as simple as tagging a static method with a CommandAttribute
:
[Command("cmd")]
public static void MyCommand (Vector3 v)
{
// Your command's code
}
and calling it like so:
~ $ cmd (1 2 3)
~ $ █
or as complicated as creating a custom class that manually parses command-line arguments. See the documentation on console commands for more information on creating your own commands.
Please feel free to contribute to this project! If you'd like to contribute, please do any of the following: