Pop*_*Car 2 c# user-interface unity-game-engine imgui
如何向编辑器文本区域添加自动换行?我试图模仿 [TextArea] 属性(自动换行,需要时自动增加高度)
我知道 GUILayout.TextArea() 有效,但我希望使用 EditorGUILayout,因为根据文档,它正确响应复制/粘贴、全选等。
我的代码:
obj.talkableFlavorText = EditorGUILayout.TextArea(obj.talkableFlavorText, GUILayout.MinHeight(textAreaHeight));
Run Code Online (Sandbox Code Playgroud)
使用 aGUIStyle并将 wordWrap 属性设置为true。
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);
}
}
Run Code Online (Sandbox Code Playgroud)
结果: