@@ -6,23 +6,27 @@ public class ConsoleGUI : MonoBehaviour {
6
6
public ConsoleAction escapeAction ;
7
7
public ConsoleAction submitAction ;
8
8
[ HideInInspector ]
9
- public string input = "" ;
9
+ public string input = "" ;
10
10
private ConsoleLog consoleLog ;
11
11
private Rect consoleRect ;
12
12
private bool focus = false ;
13
13
private const int WINDOW_ID = 50 ;
14
- private ConsoleCommandsRepository consoleCommandsRepository ;
15
14
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
+
20
24
21
25
private void Start ( ) {
22
26
consoleRect = new Rect ( 0 , 0 , Screen . width , Mathf . Min ( 300 , Screen . height ) ) ;
23
27
consoleLog = ConsoleLog . Instance ;
24
- consoleCommandsRepository = ConsoleCommandsRepository . Instance ;
25
- }
28
+ consoleCommandsRepository = ConsoleCommandsRepository . Instance ;
29
+ }
26
30
27
31
private void OnEnable ( ) {
28
32
focus = true ;
@@ -37,7 +41,7 @@ public void OnGUI() {
37
41
}
38
42
39
43
private void RenderWindow ( int id ) {
40
- if ( fixPositionNextFrame )
44
+ if ( fixPositionNextFrame )
41
45
{
42
46
MoveCursorToPos ( input . Length ) ;
43
47
fixPositionNextFrame = false ;
@@ -48,7 +52,7 @@ private void RenderWindow(int id) {
48
52
HandleUp ( ) ;
49
53
HandleDown ( ) ;
50
54
51
- GUILayout . BeginScrollView ( Vector2 . zero ) ;
55
+ GUILayout . BeginScrollView ( new Vector2 ( 0 , scrollPosition ) , false , true ) ;
52
56
GUILayout . Label ( consoleLog . log ) ;
53
57
GUILayout . EndScrollView ( ) ;
54
58
GUI . SetNextControlName ( "input" ) ;
@@ -78,7 +82,7 @@ private void MoveCursorToPos(int position)
78
82
return ;
79
83
}
80
84
81
- private void HandleTab ( )
85
+ private void HandleTab ( )
82
86
{
83
87
if ( KeyDown ( "tab" ) ) {
84
88
if ( input != "" ) { // don't do anything if the input field is still blank.
@@ -111,7 +115,7 @@ private void HandleUp()
111
115
consoleHistoryPosition += 1 ;
112
116
if ( consoleHistoryPosition > consoleHistoryCommands . Count - 1 ) consoleHistoryPosition = consoleHistoryCommands . Count - 1 ;
113
117
input = consoleHistoryCommands [ consoleHistoryPosition ] ;
114
- fixPositionNextFrame = true ;
118
+ fixPositionNextFrame = true ;
115
119
//MoveCursorToPos(input.Length);
116
120
}
117
121
}
0 commit comments