|
1 | 1 | # Command Tool for Unity 2019+
|
2 | 2 |
|
3 | 3 | ## Installation
|
4 |
| -### Option A: |
5 |
| -1) Copy this repo's .git URL |
6 |
| -2) Open Unity Package Manager |
7 |
| -3) Click '+' icon and select 'Install from git URL' |
8 |
| -4) Paste URL |
9 |
| -5) Hit Enter/Click done |
10 |
| -6) Package will install |
| 4 | +### Option A (GIT Package): |
| 5 | +1) Open Unity Package Manager |
| 6 | +2) Click '+' icon and select 'Install from git URL' |
| 7 | +3) Paste <code>https://github.com/maxfleetdev/unity-command-tool.git</code> into prompt |
| 8 | +4) Hit Enter/Click done |
| 9 | +5) Package will begin installing |
| 10 | + |
| 11 | +### Option B (Package): |
| 12 | +1) Download commander.unitypackage from latest release page |
| 13 | +2) Double click on downloaded file |
| 14 | +3) Unity will automatically install inside the open project |
| 15 | + |
| 16 | +## How To Use |
| 17 | +### Command Attribute |
| 18 | +Commands are assigned by using the <code>Command[...]</code> attribute: |
| 19 | +```c# |
| 20 | +[Command("give", "Gives player an item using ID and Quantity")] |
| 21 | +private void GiveCommand(int id, int quantity) |
| 22 | +{ |
| 23 | + ... |
| 24 | +``` |
| 25 | +Attributes have many overloads, so you can provide descriptions, hidden commands, certain role access etc (working on improving with extra attributes) |
| 26 | + |
| 27 | +Commands can be assigned in any class, static or instanced (MonoBehaviour) |
| 28 | +- Static Command methods are registered on startup automatically by CommandRegistry |
| 29 | +- Instanced Commands methods **must** be registered on creation (Awake/Start etc) |
| 30 | + |
| 31 | +### Static Command Example: |
| 32 | +```c# |
| 33 | +[Command("give", "Gives player an item using ID and Quantity")] |
| 34 | +private static void GiveCommand(int id, int quantity) |
| 35 | +{ |
| 36 | + AddItem(id, quantity); |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | +### Instance Command Example: |
| 41 | +```c# |
| 42 | +private void Awake() |
| 43 | +{ |
| 44 | + // Called Only Once |
| 45 | + CommandRegistry.RegisterInstanceCommands(this); |
| 46 | +} |
| 47 | + |
| 48 | +[Command("give", "Gives player an item using ID and Quantity")] |
| 49 | +private static void GiveCommand(int id, int quantity) |
| 50 | +{ |
| 51 | + AddItem(id, quantity); |
| 52 | +} |
| 53 | +``` |
0 commit comments