首页 > 解决方案 > 使用 EditorGUILayout.PropertyField 时可以删除这个大空间吗?

问题描述

我开始在 Unity 中编写编辑器脚本,并且很快就被整个 SerializedProperty 事物所吸引。我要做的就是让这个区分大小写的复选框粘在检查器的右侧,文本和框本身之间没有所有空间,为 TextField 留出足够的空间。

这就是我目前正在做的事情:

using (new EditorGUILayout.HorizontalScope())
{
    GUILayout.Label("Search for:", GUILayout.Width(64));
    searchText = GUILayout.TextField(searchText);
    EditorGUILayout.PropertyField(propCaseSensitive, GUILayout.MinWidth(0), GUILayout.ExpandWidth(false));
}

这就是我得到的

我试过 GUILayout.Width 和 GUILayout.MaxWidth 和 GUILayout.ExpandWidth(false) 结合 GUILayout.MinWidth (也只是他们自己)

这些都没有奏效,我一直试图让这个简单的脚本工作太久,以至于我无法承认,这让我发疯了。请帮帮我,谢谢:)

标签: c#unity3d

解决方案


我认为您可以像其他标签一样进行操作。

PropertyField有超载GUIContent label。通过传入,GUIContent.none您可以省略标签,而是添加您自己的标签:

                                                          // Not sure if even needed but adjust to the width you need
EditorGUILayout.LabelField(propCaseSensitive.displayName, GUILayout.Width(64), GUILayout.ExpandWidth(false));
                                                 // Don't draw the name via the default property field layout
EditorGUILayout.PropertyField(propCaseSensitive, GUIContent.none, GUILayout.ExpandWidth(false));

推荐阅读