Coder Social home page Coder Social logo

voltstro-studios / unitycommandlineparser Goto Github PK

View Code? Open in Web Editor NEW
38.0 3.0 2.0 207 KB

Simple command line argument parser for Unity

License: MIT License

C# 100.00%
unity unity3d unity2d unity-scripts unity-script csharp unity-package commandlineparser

unitycommandlineparser's Introduction

UnityCommandLineParser

License Discord YouTube

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.

Features

  • Parses launch arguments when the player is launched.
  • Supports commands and arguments

Getting Started

Package Installation

Prerequisites

Unity 2020.3.x

Installation Methods

There are three main sources on how you can install this package. Pick which ever one suites you the best!

Voltstro UPM

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.

OpenUPM

You can install this package via OpenUPM.

To install it, use their CLI:

openupm-cli add dev.voltstro.unitycommandlineparser

Git

To install it via the package manager with git you will need to:

  1. Setup UnityNuGet
  2. Open up the package manager via Windows -> Package Manager
  3. Click on the little + sign -> Add package from git URL...
  4. Type https://github.com/Voltstro-Studios/UnityCommandLineParser.git and add it
  5. Unity will now download and install the package

Please 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.

Usage

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.

Examples

[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.

Authors

Voltstro - Initial Work - Voltstro

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

unitycommandlineparser's People

Contributors

voltstro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.