VR Development Framework
v 1.0.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
AVR_DevConsoleMirror.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using UnityEngine.UI;
5 
6 namespace AVR.Core {
7  // TODO: This class is outdated. It makes no use of settings-keybindings and the history is wrong. Look to AVR_BasicDevConsole.
8 
9  /// <summary>
10  /// Mirrors the output of the DevConsole onto a Text component.
11  /// To use, simply assign "DevConsoleOutput" to a Text Component that represents the output-terminal.
12  /// Assign "DevConsoleInput" to an inputfield representing the user input.
13  /// To submit a command, the user may use the keybinding specified as the /settings/core/devConsole/submitConsoleKey setting.
14  /// </summary>
15  [AVR.Core.Attributes.DocumentationUrl("class_a_v_r_1_1_core_1_1_a_v_r___dev_console_mirror.html")]
17  {
18  public Text DevConsoleOutput;
19 
20  public InputField DevConsoleInput;
21 
22  private int history_index = 0;
23  private KeyCode toggleKey;
24  private KeyCode offKey;
25  private KeyCode submitKey;
26 
27  void Awake() {
28  if(!DevConsoleOutput) DevConsoleOutput = GetComponent<Text>();
29  if(!DevConsoleOutput) AVR_DevConsole.error("DevConsoleMirror " + gameObject.name + " does not have a Text Component!");
30  }
31 
32  void OnEnable() {
33  if(DevConsoleInput) {
34  // Focus inputfield automatically when we show this window. We do this on a slight delay. Otherwise it doesn't work.
35  Invoke("FocusInputField", 0.01f);
36  }
37  }
38 
39  private void FocusInputField() {
40  DevConsoleInput.Select();
41  DevConsoleInput.ActivateInputField();
42  }
43 
44  void OnGUI() {
45  DevConsoleOutput.text = AVR_DevConsole.get_text();
46 
47  if(DevConsoleInput) {
48  if(Input.GetKeyDown(KeyCode.UpArrow)) {
49  DevConsoleInput.text = AVR_DevConsole.history(history_index);
50  history_index++;
51  }
52  else if (Input.GetKeyDown(KeyCode.DownArrow))
53  {
54  history_index--;
55  DevConsoleInput.text = AVR_DevConsole.history(history_index);
56  }
57  if(DevConsoleInput.isFocused && DevConsoleInput.text != "" && Input.GetKey(AVR.Core.AVR_Settings.get_key("/settings/core/devConsole/submitConsoleKey")))
58  {
59  run_command();
60  FocusInputField(); // Re-focus inputfield for further commands
61  }
62  }
63  }
64 
65  /// <summary>
66  /// Run the command that is written in DevConsoleInput.
67  /// </summary>
68  public void run_command() {
69  history_index = 0;
70  if(!DevConsoleInput) {
71  AVR_DevConsole.error("DevConsoleMirror " + gameObject.name + " tried to run a command, but no input component was assigned!");
72  return;
73  }
74  AVR_DevConsole.command(DevConsoleInput.text);
75  DevConsoleInput.text = "";
76  }
77  }
78 }
Monobehaviour but with an added URL button to a documentation page.
Sets the documentation html file inside of Packages/com.avr.core/Documentation/html of a given class...
void run_command()
Run the command that is written in DevConsoleInput.
Mirrors the output of the DevConsole onto a Text component. To use, simply assign "DevConsoleOutput" ...