我正试图在Unity中创建一个终端模拟器。我能够输入文本并将其显示为上面的输出,当通过ScrollView输入足够多的文本时,输出将生成一个滚动条。
但是,当用户输入文本时,我不知道如何使滚动条跳到底部。
这是用于绘制GUI窗口的方法。
// relevant instance variables
private Rect _windowPosition = new Rect();
List<string> output = new List<string>();
string user_input = "";
Vector2 scroll_pos = new Vector2(1,1);
...
...
...
private void onWindow(int windowID){
GUILayout.BeginVertical();
// Output is placed here. Is Scrollable
scroll_pos = GUILayout.BeginScrollView( scroll_pos );
GUILayout.Label( String.Join("\n", output.ToArray()) );
GUILayout.EndScrollView();
// Output ends here. Next piece is user input
user_input = GUILayout.TextField(user_input);
if (Event.current.Equals(Event.KeyboardEvent("return"))) {
output.Add(user_input);
user_input = ""; //clears the TextField
scroll_pos.x = 1;
scroll_pos.y = 1;
}
GUILayout.EndVertical();
GUI.DragWindow();
}从我的搜索中,我看到它说我应该更改scroll_pos变量,因为它用于控制/读取滚动条的位置。滚动条的值在0- 1之间规范化.
我尝试将scroll_pos值同时设置为0和1,但没有影响。除此之外,我不知道如何处理这个问题。
发布于 2015-08-12 20:13:48
试着改变
scroll_pos.x = 1;
scroll_pos.y = 1;至
scroll_pos.y += 9999;如果你也想用X强制滚动,但通常控制台不会生成水平滚动,它们会根据你配置的列数强制换行。
https://stackoverflow.com/questions/31972772
复制相似问题