A develop console for Unity let you input command string to execute debug functions.
######Read Chinese Version中文版
- Copy JumpCommand directory to your project folder.
- Create a GameObject in the scene and add a JumpCommandGUI component to it.
- Run your game and press
~
to open command input. - Input some command and press
Enter
to execute, press↑
and↓
to get history command. - Press
~
again to close command input.
JumpCommand can only register static function and class function that inherited from Monobehaviour. If the function's parameter type is not native type(int, float, double, string, bool, enum), you will need write Type Converter for you custom parameter type.
- Add CommandItem to function
- If the function is Monobehaviour, you need select GameObject at Hierarchy window when you call it.
Here is a example:
[CommandItem("test","output integer")]
static public void CommandTest(int i) {
Debug.Log(i.ToString());
}
We have registered a command named test
with help text "output integer", build-in command ls
can list all commands and help text. Now input test 10
as a command we can get a output message 10
in Console.
If you want to change a person's speed from command like speed 0.5
, add CommandItem to AdjustSpeed, and make sure when you input the command you have selected the GameObject you want to invoke.
//Person.cs
public class Person : MonoBehaviour {
//...
[CommandItem("speed","Change person speed")]
public void AdjustSpeed(float value) {
speed += value;
}
//...
}
If the function is static, just add CommandItem and call it. If the function is Monobehaviour class, add CommandItem and select the GameObject when you call it.
Most native data types (int, float, double, string, bool, enum) have default type converters, so you don't need to write converts for them. JumpCommand can convert string arguments to proper parameters. If you want to use custom parameter type, you need to write Type Converter for your type. There is a reference How to: Implement a Type Converter at MSDN show you how to write a converter to convert string to Point class.
Feel free to ask me any question.