public static string TextArea (string text, params GUILayoutOption[] options);
public static string TextArea (string text, GUIStyle style, params GUILayoutOption[] options);

参数

text要编辑的文本。
style可选 GUIStyle
options一个可选的布局选项列表,用于指定额外的布局属性。此处传递的任何值都将覆盖 style 定义的设置。
另请参阅:GUILayout.WidthGUILayout.HeightGUILayout.MinWidthGUILayout.MaxWidthGUILayout.MinHeightGUILayout.MaxHeightGUILayout.ExpandWidthGUILayout.ExpandHeight

返回

string 用户输入的文本。

描述

创建一个文本区域。

此方法的运行方式与 GUILayout.TextArea 一样,但能够正确响应编辑器中的 Select All、Copy、Paste 等操作。

\ 快速脚本编辑器。

// Simple script that lets you visualize your scripts in an editor window
// This can be expanded to save your scripts also in the editor window.

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor;

public class TextAreaExample : EditorWindow { string text = "Nothing Opened..."; TextAsset txtAsset; Vector2 scroll;

[MenuItem("Examples/TextArea usage")] static void Init() { TextAreaExample window = (TextAreaExample)GetWindow(typeof(TextAreaExample), true, "EditorGUILayout.TextArea"); window.Show(); }

Object source;

void OnGUI() { source = EditorGUILayout.ObjectField(source, typeof(Object), true); TextAsset newTxtAsset = (TextAsset)source;

if (newTxtAsset != txtAsset) ReadTextAsset(newTxtAsset);

scroll = EditorGUILayout.BeginScrollView(scroll); text = EditorGUILayout.TextArea(text, GUILayout.Height(position.height - 30)); EditorGUILayout.EndScrollView(); }

void ReadTextAsset(TextAsset txt) { text = txt.text; txtAsset = txt; } }