In-Game Console Screenshot
In the process of learning more about network code in unity, to our eventual goal of making an online game that is peer-to-peer it became useful to have an in-game console (like old school fps consoles that pop down from the top of the screen). I made a pretty good implementation of a console that works very well and is really easy to expand.
Console.Log(“message”); // create a message in the log
The above example would print the message to the log, (a timestamp would be printed before it). All of the needed functions for the console are static so they can be accessed easily from anywhere. This includes the following function, ‘Console.AddCommand’ and the above ‘Console.Log’.
Console.AddCommand(new ConsoleCommand(“command”,
“help text displayed, when help is called”,
CmdParameterType.None, targetGameObject,
“MethodInGameObject”)); // This method (And class) creates a new console command
The above example, would work like so, type “command” into the console, and the targetGameObject would have a ‘SendMessage’ fired to ‘MethodInGameObject’
The console commands work in a very simplistic way, they simply handle a SendMessage operation for you, as well as parsing your parameter into something useful for the receiving message method. So far the supported parameter types are, int, float, string, gameobject(a string that is used to preform a ‘GameObject.Find’ operation), Vector3 and Vector2. If anyone has any suggestions for more supported parameter types id love to hear them, but keep in mind, due to the fact this all works via SendMessage, only one parameter is possible, however, you can send a string and parse in the reviving message method.
I also plan on writing some default commands, right now there is just a help command that prints out all of the bound commands, and when a command is added after words (‘help’) it will print out the help text created with the command. I’m also looking for suggestions on what kind of default commands would be useful, so please, comment away! Apon completion it will become available on the unity asset store.