Dynamic commands
Adding commands at runtime
private void Start()
{
// The method doesn't return anything, so we'll create an Action.
CommandExecutor.AddCommand("hello", new Action<string>(Hello));
}
private void Hello(string message)
{
Debug.Log(message);
}private void Start()
{
// The method returns a value, so we'll create Func in this case.
CommandExecutor.AddCommand("multiply", new Func<int, int, int>(Multiply));
}
private int Multiply(int a, int b)
{
return a * b;
}private void Start()
{
// Alternatively you could create the delegate with a lambda expression.
CommandExecutor.AddCommand("hello", new Action<string>((string message) =>
{
Debug.Log(message);
}));
}Removing commands at runtime
CommandExecutor.RemoveCommand("quit");Last updated