Version: 2020.2

GUI.TextArea

切换到手册
public static string TextArea (Rect position, string text);
public static string TextArea (Rect position, string text, int maxLength);
public static string TextArea (Rect position, string text, GUIStyle style);
public static string TextArea (Rect position, string text, int maxLength, GUIStyle style);

参数

position 屏幕上用于文本字段的矩形。
text 要编辑的文本。应将该函数的返回值指定给该字符串,如示例中所示。
maxLength 字符串的最大长度。如果省略,用户可以键入任意长度的字符串。
style 要使用的样式。如果省略,则使用当前 GUISkintextArea 样式。

返回

string 编辑后的字符串。

描述

创建一个可供用户编辑字符串的多行文本区域。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public string stringToEdit = "Hello World\nI've got 2 lines...";

void OnGUI() { // Make a multiline text area that modifies stringToEdit. stringToEdit = GUI.TextArea(new Rect(10, 10, 200, 100), stringToEdit, 200); } }