Commands
The [Command]
attribute has the following members that can customise and alter the generated command:
alias
- the name of the command in the Quantum Console; defaults to the name of the member it is used ondescription
- description of the command that will be used in command manual generation; defaults to emptysupportedPlatforms
- a bitwise enum specifying which platforms the command will be loaded on; defaults toPlatform.All
monoTarget
- see Non-static usage for more; defaults toMonoTargetType.Single
See the API Reference for the available constructors
Multiple Commands
Quantum Console allows the usage of multiple [Command]
s on a single member to create aliases for a single command.
To prevent it being a chore of repeating the description and other aspects several times, there are additional attributes
that you can add to the member.
[CommandDescription]
- this description will be superseded by any defined in the[Command]
[CommandPlatform]
- this enum will supersede that defined by the[Command]
Static Usage
Using static functions, properties and fields as commands is very easy. Here are 4 examples:
[Command]
private static void cmd(int a) { }
In scenario 1, a command called cmd
will be generated that has no return type and takes an argument of type int
[Command("int-prop")]
protected static int someInt { get; private set; }
In scenario 2, two commands called int-prop
will be generated:
- The first will take 0 arguments and will return an int; this uses the
property.get
- The second will take 1 argument of type int and will not return; this uses the
property.set
[Command("bool-field")]
public static bool someBool;
In scenario 3, two commands will be generated called bool-field
.
Fields are treated as auto-properties, so this will behave like scenario 2
[Command("del")]
public static Func<bool> someDelegate;
In scenario 4, a command will be generated called del
.
Delegate are treated as a normal method, so this will behave like scenario 1
Delegate fields must be strongly typed, this means the following is not allowed:
[Command("del")]
public static Delegate someDelegate;
Non-static Usage
Non-static usage has more caveats than static usage, but is still very simple. Non-static commands require that either
- The declaring class is a MonoBehaviour type.
- The Quantum Registry is used. See here
This is because the object needs to be found in the scene to invoke the command on.
Non-static commands introduce another concept called the MonoTargetType
- this defines how to select the target for invocation
See the API Reference for the available types
The following example creates two commands from the same method:
kill-all
, that will callDie
on all active instances ofEnemy
kill
, that will callDie
on a single instance ofEnemy
, provided as an argument
using QFSW.QC;
using UnityEngine;
public class Enemy : MonoBehaviour
{
[Command("kill-all", MonoTargetType.All)]
[Command("kill", MonoTargetType.Argument)]
private void Die()
{
// Death implementation here
}
}
Restrictions
In order to prevent command invocation ambiguity, commands must be unique by name or arg count. This means two commands having the same alias is legal, but must have different arg counts
If they have the same arg count and the same name, you must override the alias to make them unique.
Additionally, all parameters must be of a supported types. A partial list of supported parameter types is as follows:
int
float
decimal
double
string
bool
byte
sbyte
uint
short
ushort
long
Vector2
Vector3
Vector4
Quaternion
Color
Type
ulong
char
GameObject
- all types deriving from
Component
orMonoBehaviour
Array
List<T>
Stack<T>
Queue<T>
granted that the element type is also supported- all
enum
types
See Parsers for all supported types
See Custom Parsers for adding new types
If either of these restrictions are broken, the Quantum Console Processor will discard the command and throw a warning