【问题标题】:How can I add word wrap to EditorGUILayout.TextArea?如何将自动换行添加到 EditorGUILayout.TextArea?
【发布时间】:2020-12-25 01:47:03
【问题描述】:

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

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

我的代码:

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

【问题讨论】:

  • 你只有一个很长的“单词”。它应该在哪里包裹?您是否尝试过使用更常规的文本?
  • 它分配的 GUIStyle 有一个属性 word-wrap - 你测试过吗?
  • 也许这是一个不好的例子,即使是正常的单词它仍然不会换行,它只是继续正确。我现在尝试了 GUI.skin.textArea.wordWrap = true 但我仍然得到相同的结果。

标签: c# unity3d user-interface imgui


【解决方案1】:

使用 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);
    }
}

结果:

【讨论】:

    猜你喜欢
    • 2011-06-13
    • 2015-02-01
    • 2020-05-13
    • 1970-01-01
    • 2014-06-12
    • 1970-01-01
    • 2020-12-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多