c# - 如何向 EditorGUILayout.TextArea 添加自动换行?

标签 c# unity-game-engine user-interface imgui

Picture showing lack of word wrap in textarea

如何向编辑器文本区域添加自动换行?我正在尝试模仿 [TextArea] 属性(自动换行,需要时自动增加高度)

我知道 GUILayout.TextArea() 可以工作,但我希望使用 EditorGUILayout,因为根据文档,它可以正确响应复制/粘贴、全选等。

我的代码:

obj.talkableFlavorText = EditorGUILayout.TextArea(obj.talkableFlavorText, GUILayout.MinHeight(textAreaHeight));

最佳答案

使用GUIStyle并将wordWrap属性设置为true

基于Unity Editor Window Example的完整示例

using UnityEngine;
using UnityEditor;

public class MyWindow : EditorWindow
{
    string myString = "Hello World";

    // Add menu named "My Window" to the Window menu
    [MenuItem("Window/My Window")]
    static void Init()
    {
        // Get existing open window or if none, make a new one:
        MyWindow window = (MyWindow)EditorWindow.GetWindow(typeof(MyWindow));
        window.Show();
    }

    void OnGUI()
    {
        GUIStyle style = new GUIStyle(EditorStyles.textArea);
        style.wordWrap = true;
        myString = EditorGUILayout.TextArea(myString, style);
    }
}

结果:

enter image description here

关于c# - 如何向 EditorGUILayout.TextArea 添加自动换行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63764003/

相关文章:

c# BitConverter.GetBytes(float/double) 格式?

c# - XAML 绑定(bind)中 IntelliSense 自动完成的强制类型

unity-game-engine - 将参数预先应用到 unityscript 函数并将其用作发送到另一个函数的对象

.net - 如何使WCF服务STA(单线程)

c# - C# 中的深层克隆对象

unity-game-engine - ParseFacebookUtils.LogInAsync 仅在 WebPlayer 上给出错误

unity-game-engine - 通过脚本隐藏/取消隐藏 Unity3D 中的对象

java - 如何在没有 Eclipse 的情况下使用 SWT?

java - 如何在锚定 Pane 中居中 ImageView ?

c# - 强制方法不返回 null