Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void SubmitString()
- {
- //saves string for processing
- _currentLine = console.text;
- //stops if string is empty
- if(_currentLine == "")
- {
- return;
- }
- //logs previous input
- Color consoleColor = consoleActiveText.color;
- GameObject tempText = Instantiate(previousInputText, consoleContainer.transform);
- tempText.transform.position = console.transform.position;
- tempText.GetComponent<TextMeshProUGUI>().text = _currentLine;
- tempText.GetComponent<TextMeshProUGUI>().color = consoleColor;
- //Response...
- GameObject tempResponse = Instantiate(previousInputText, consoleContainer.transform);
- tempResponse.transform.position = console.transform.position;
- tempResponse.transform.position -= new Vector3(0, 7f, 0);
- StringProcessor(_currentLine, tempResponse);
- console.transform.position -= new Vector3(0, 14f, 0);
- //resets console
- console.text = null;
- //Check if console is out of bounds
- // while(console.transform.position.y < (-50f))
- // {
- // consoleContainer.transform.position += new Vector3(0, 14f, 0);
- // }
- ConsoleFocus();
- }
- private void StringProcessor(string line, GameObject output)
- {
- var command = Regex.Match(line, @"^([\w\-]+)");
- foreach (string commands in knownCommands)
- {
- if (string.Equals(commands, command.ToString().ToUpper()))
- {
- //command exists call with 1 parameter
- try
- {
- StartCoroutine(COMMAND(command.ToString().ToUpper(), line.ToString().Split(' ')[1], output.GetComponent<TextMeshProUGUI>()));
- return;
- }
- catch
- {
- output.GetComponent<TextMeshProUGUI>().text = "Missing second parameter";
- return;
- }
- }
- }
- //unrecognized
- string response = ("Unrecognized command: '" + command + "'");
- output.GetComponent<TextMeshProUGUI>().text = response;
- return;
- }
- private void ConsoleFocus()
- {
- console.enabled = true;
- EventSystem.current.SetSelectedGameObject(console.gameObject, null);
- console.OnPointerClick(new PointerEventData(EventSystem.current));
- }
- private void ConsoleUnfocus()
- {
- EventSystem.current.SetSelectedGameObject(null);
- console.enabled = false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement