public void Update()
 {
     consoleLog.transform.parent.GetComponent <RectTransform>().sizeDelta = new Vector2(consoleLog.transform.parent.GetComponent <RectTransform>().sizeDelta.x, CommandBackend.consoleSize);
     if (consoleLog.text != CommandBackend.consoleLog)
     {
         consoleLog.transform.parent.parent.parent.GetComponent <ScrollRect>().normalizedPosition = new Vector2(0, 0);
     }
     consoleLog.text = CommandBackend.consoleLog;
     if (Input.GetButtonDown("Submit"))
     {
         if (!CommandBackend.currentlyActive)
         {
             consoleWindow.gameObject.SetActive(true);
             CommandBackend.currentlyActive = true;
         }
         else if (!CommandBackend.executing && consoleInput.text != "")
         {
             string   command = consoleInput.text.Split(' ')[0];
             int      i       = consoleInput.text.IndexOf(" ") + 1;
             string[] args;
             if (i == 0) //repeats the original command ???
             {
                 args = new string[0];
             }
             else
             {
                 args = consoleInput.text.Substring(i).Split(' ');
             }
             CommandBackend.IncreaseOutputSize(CommandBackend.line);
             CommandBackend.PrintOutput("] " + consoleInput.text);
             consoleInput.text = "";
             CommandBackend.HandleConCommand(command, args);
         }
         consoleInput.Select();
         consoleInput.ActivateInputField();
     }
     else if (Input.GetButtonDown("Pause"))
     {
         consoleWindow.gameObject.SetActive(false);
         CommandBackend.currentlyActive = false;
     }
 }
Esempio n. 2
0
 void Start()
 {
     CommandBackend.AddConCommand("noclip", (string[] args) =>
     {
         noClip = !noClip;
         flying = noClip;
         CommandBackend.IncreaseOutputSize(CommandBackend.line);
         return("NoClip = " + noClip + "\nFlying = " + flying);
     }, "Toggle player collisions and flying.", CommandBackend.CommandType.Cheat);
     CommandBackend.AddConCommand("fly", (string[] args) =>
     {
         flying = !flying;
         return("Flying = " + flying);
     }, "Toggle player flying.", CommandBackend.CommandType.Cheat);
     CommandBackend.AddConCommand("speed", (string[] args) =>
     {
         if (args == null || args.Length == 0)
         {
             CommandBackend.IncreaseOutputSize(CommandBackend.line);
             return("Player speed is set to " + playerSpeed + ".\nUsage: speed [float]");
         }
         else
         {
             playerSpeed = float.Parse(args[0]);
             return("Desired speed has been set.");
         }
     }, "Sets the player speed.", CommandBackend.CommandType.Cheat);
     CommandBackend.AddConCommand("jumpheight", (string[] args) =>
     {
         if (args == null || args.Length == 0)
         {
             CommandBackend.IncreaseOutputSize(CommandBackend.line);
             return("Player jump height is set to " + jumpHeight + ".\nUsage: jumpheight [float]");
         }
         else
         {
             jumpHeight = float.Parse(args[0]);
             return("Desired jump height has been set.");
         }
     }, "Sets the player jump height.", CommandBackend.CommandType.Cheat);
 }
 public void Start()
 {
     CommandBackend.AddConCommand("help", (string[] args) =>
     {
         string helpmenu = "";
         if (args == null || args.Length == 0)
         {
             helpmenu = "Commands:";
             foreach (KeyValuePair <string, ConCommand> conCommand in CommandBackend.commands)
             {
                 if (conCommand.Value.type <= CommandBackend.allowedCommands)
                 {
                     helpmenu += "\n- " + conCommand.Key;
                     CommandBackend.IncreaseOutputSize(CommandBackend.line);
                 }
             }
             helpmenu += "\nUsage: help [string]";
         }
         else
         {
             CommandBackend.IncreaseOutputSize(CommandBackend.commands[args[0]].helpOutputIncrement);
             helpmenu += "\"" + CommandBackend.commands[args[0]].help + "\"";
         }
         return(helpmenu);
     }, "Displays the help menu.");
     CommandBackend.AddConCommand("exit", (string[] args) =>
     {
         consoleWindow.gameObject.SetActive(false);
         CommandBackend.currentlyActive = false;
         return("Exiting console window...");
     }, "Exits the console window.");
     CommandBackend.AddConCommand("quit", (string[] args) =>
     {
         Application.Quit();
         #if UNITY_EDITOR
         EditorApplication.ExitPlaymode();
         #endif
         return("Successfuly quit the game.");
     }, "Quits the game.");
     CommandBackend.AddConCommand("clear", (string[] args) =>
     {
         CommandBackend.consoleLog = "";
         consoleLog.text           = "";
         CommandBackend.SetOutputSize(CommandBackend.line);
         return("Type \"exit\" to exit this console window.");
     }, "Clears and resets the console window.");
     CommandBackend.AddConCommand("fontsize", (string[] args) =>
     {
         if (args == null || args.Length == 0)
         {
             CommandBackend.IncreaseOutputSize(CommandBackend.line);
             return("Font size is set to " + consoleLog.fontSize + ".\nUsage: fontsize [int]");
         }
         else
         {
             consoleLog.fontSize = int.Parse(args[0]);
             return("Desired size has been set.");
         }
     }, "Sets the font size of the console window.");
     CommandBackend.AddConCommand("nextmap", (string[] args) =>
     {
         int index = SceneManager.GetActiveScene().buildIndex + 1;
         SceneManager.LoadScene(index);
         return("Loaded " + index + "!");
     }, "Loads the next map in order.");
     CommandBackend.AddConCommand("lastmap", (string[] args) =>
     {
         int index = SceneManager.GetActiveScene().buildIndex - 1;
         if (index >= 0)
         {
             SceneManager.LoadScene(index);
             return("Loaded " + index + "!");
         }
         else
         {
             return("Map index " + index + " is out of range!");
         }
     }, "Loads the next map in order.");
     CommandBackend.AddConCommand("allowcheats", (string[] args) =>
     {
         if (CommandBackend.allowedCommands < CommandBackend.CommandType.Cheat)
         {
             CommandBackend.allowedCommands = CommandBackend.CommandType.Cheat;
             return("Cheats have been enabled.");
         }
         else
         {
             return("The allowed commands are set to a higher enum than the parameter.");
         }
     }, "Activates cheats.");
     #if UNITY_EDITOR
     CommandBackend.AddConCommand("allowdev", (string[] args) =>
     {
         if (CommandBackend.allowedCommands < CommandBackend.CommandType.Developer)
         {
             CommandBackend.allowedCommands = CommandBackend.CommandType.Developer;
             return("Developer mode has been enabled.");
         }
         else
         {
             return("The allowed commands are set to a higher enum than the parameter.");
         }
     }, "Activates developer mode.");
     #endif
 }