Moved DebugConsole initialization to the ctr to enable printing in Starts.

This commit is contained in:
excitedneon 2017-05-08 04:16:01 +03:00
parent d99719b66f
commit 593f1ca9f8

View File

@ -14,6 +14,40 @@ public class DebugConsole : MonoBehaviour {
private Dictionary<string, DebugConsoleAction> Actions = new Dictionary<string, DebugConsoleAction>();
public DebugConsole() {
AddCommand("help", "Lists all commands.", (args) => {
Println("Commands:");
foreach (string Action in Actions.Keys) {
Println("- " + Action);
}
});
AddCommand("help (command)", "Describes the given command.", (args) => {
// Check complete versions of the names (so you can do eg. help "help (command)")
foreach (string Action in Actions.Keys) {
if (Action.Equals(args[0])) {
Println(Actions[Action].Description);
return;
}
}
// Check just names
foreach (string Action in Actions.Keys) {
string[] Parts = Action.Split(' ');
if (Parts[0].Equals(args[0])) {
Println(Actions[Action].Description);
return;
}
}
Println("That command doesn't exist.");
});
AddCommand("print (text)", "Prints the given text.", (args) => {
Println(args[0]);
});
Term.SetDebugConsole(this);
}
public void CallCommand() {
if (InputField.text.Length == 0) {
return;
@ -60,40 +94,6 @@ public class DebugConsole : MonoBehaviour {
TextField.text += text;
}
private void Start() {
AddCommand("help", "Lists all commands.", (args) => {
Println("Commands:");
foreach (string Action in Actions.Keys) {
Println("- " + Action);
}
});
AddCommand("help (command)", "Describes the given command.", (args) => {
// Check complete versions of the names (so you can do eg. help "help (command)")
foreach (string Action in Actions.Keys) {
if (Action.Equals(args[0])) {
Println(Actions[Action].Description);
return;
}
}
// Check just names
foreach (string Action in Actions.Keys) {
string[] Parts = Action.Split(' ');
if (Parts[0].Equals(args[0])) {
Println(Actions[Action].Description);
return;
}
}
Println("That command doesn't exist.");
});
AddCommand("print (text)", "Prints the given text.", (args) => {
Println(args[0]);
});
Term.SetDebugConsole(this);
}
private void Update() {
if (Input.GetButtonDown("Console Toggle")) {
Visible = !Visible;