Simple command line argument parser for Unity
MIT License
A command line parser for Unity.
One of the issues that plague most C# command line parsers is that they are designed to be run from Program.Main(string[] args);
and basically take over as the entry point of your C# app. However, Unity doesn't have the standard C# entry point. So we created this project, a command line parser for Unity that is easy to use.
This project uses McMaster.Extensions.CommandLineUtils as its underlying parsing library and provides attributes to mark fields that can be filled out by an argument. You can use any field type that CommandLineUtils supports by default.
Unity 2020.3.x
There are three main sources on how you can install this package. Pick which ever one suites you the best!
You can install this package from our custom UPM registry. To setup our registry, see here.
Once you have the registry added to your project, you can install it like any other package via the package manager.
You can install this package via OpenUPM.
To install it, use their CLI:
openupm-cli add dev.voltstro.unitycommandlineparser
To install it via the package manager with git you will need to:
https://github.com/Voltstro-Studios/UnityCommandLineParser.git
and add itPlease note that you will have to manually check for updates, and replace the hash (or tag version) in your project's packages-lock.json
file.
Mark a static field with a [CommandLineArgument]
attribute to be able to be set as a command line argument.
Or you can mark a static method with a [CommandLineCommand]
attribute to be able to run a method as a command line argument.
[CommandLineArgument("name", "Sets the name of the player")]
public static string Name = "Voltstro";
[CommandLineArgument("fps", "Sets the fps of the game.")]
public static int Fps = 60;
[CommandLineCommand("weapons", "Adds all default weapons to the player on load")]
public static void AddDefaultWeapons()
{
//Do some cool stuff
}
If this example was to be run with the commands: ./UnityPlayer -fps 420 -name "EternalClickbait Suxs" -weapons
, it would set the Fps
variable to 420
, set the Name
variable to EternalClickbait Suxs
and run the method AddDefaultWeapons()
on startup.
Voltstro - Initial Work - Voltstro
This project is licensed under the MIT License - see the LICENSE.md file for details.