EditorGUILayout.TextArea

Unity · Версия 2020.3 LTS · Scripting · EditorGUILayout

EditorGUILayout.TextArea

Объявление

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

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

Параметры

text Текст для редактирования.
style Необязательный стиль GUIStyle.
options Необязательный список параметров макета, определяющих дополнительные свойства макета. Любые переданные здесь значения переопределяют настройки, заданные стилем..
Смотрите так же: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.

Возвращает

string Текст, введенный пользователем.

Описание

Создать текстовую область.

Это работает так же, как GUILayout.TextArea, но корректно реагирует на команды "Выбрать все", "Копировать", "Вставить" и т. д. в редакторе.

Быстрый редактор сценариев.
// Простой скрипт, позволяющий визуализировать ваши скрипты в окне редактора
// Это можно расширить, чтобы сохранить ваши скрипты также в окне редактора.

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;
    }
}

Обновлено 17 ноября 2026 г.