Skip to content

Commit 23cf3d4

Browse files
committed
2 parents 038c221 + 33a0311 commit 23cf3d4

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

Console/Scripts/ConsoleGUI.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,27 @@ public class ConsoleGUI : MonoBehaviour {
66
public ConsoleAction escapeAction;
77
public ConsoleAction submitAction;
88
[HideInInspector]
9-
public string input = "";
9+
public string input = "";
1010
private ConsoleLog consoleLog;
1111
private Rect consoleRect;
1212
private bool focus = false;
1313
private const int WINDOW_ID = 50;
14-
private ConsoleCommandsRepository consoleCommandsRepository;
1514

16-
private int maxConsoleHistorySize = 100;
17-
private int consoleHistoryPosition = 0;
18-
private List<string> consoleHistoryCommands = new List<string>();
19-
private bool fixPositionNextFrame = false; // a hack because the up arrow moves the cursor to the first position.
15+
private ConsoleCommandsRepository consoleCommandsRepository;
16+
17+
private int maxConsoleHistorySize = 100;
18+
private int consoleHistoryPosition = 0;
19+
private List<string> consoleHistoryCommands = new List<string>();
20+
private bool fixPositionNextFrame = false; // a hack because the up arrow moves the cursor to the first position.
21+
22+
private int scrollPosition;
23+
2024

2125
private void Start() {
2226
consoleRect = new Rect(0, 0, Screen.width, Mathf.Min(300, Screen.height));
2327
consoleLog = ConsoleLog.Instance;
24-
consoleCommandsRepository = ConsoleCommandsRepository.Instance;
25-
}
28+
consoleCommandsRepository = ConsoleCommandsRepository.Instance;
29+
}
2630

2731
private void OnEnable() {
2832
focus = true;
@@ -37,7 +41,7 @@ public void OnGUI() {
3741
}
3842

3943
private void RenderWindow(int id) {
40-
if (fixPositionNextFrame)
44+
if (fixPositionNextFrame)
4145
{
4246
MoveCursorToPos (input.Length);
4347
fixPositionNextFrame = false;
@@ -48,7 +52,7 @@ private void RenderWindow(int id) {
4852
HandleUp ();
4953
HandleDown ();
5054

51-
GUILayout.BeginScrollView(Vector2.zero);
55+
GUILayout.BeginScrollView(new Vector2(0, scrollPosition), false, true);
5256
GUILayout.Label(consoleLog.log);
5357
GUILayout.EndScrollView();
5458
GUI.SetNextControlName("input");
@@ -78,7 +82,7 @@ private void MoveCursorToPos(int position)
7882
return;
7983
}
8084

81-
private void HandleTab()
85+
private void HandleTab()
8286
{
8387
if (KeyDown ("tab")) {
8488
if (input != "") { // don't do anything if the input field is still blank.
@@ -111,7 +115,7 @@ private void HandleUp()
111115
consoleHistoryPosition += 1;
112116
if (consoleHistoryPosition > consoleHistoryCommands.Count - 1) consoleHistoryPosition = consoleHistoryCommands.Count - 1;
113117
input = consoleHistoryCommands[consoleHistoryPosition];
114-
fixPositionNextFrame = true;
118+
fixPositionNextFrame = true;
115119
//MoveCursorToPos(input.Length);
116120
}
117121
}

Console/Scripts/ConsoleLog.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ public static ConsoleLog Instance {
1313
}
1414

1515
public string log = "";
16+
public int scrollLength;
1617

1718
public void Log(string message) {
1819
log += message + "\n";
20+
scrollLength += 20;
1921
}
2022
}

0 commit comments

Comments
 (0)