所以我想格式化我正在处理的自定义EditorWindow
我在横向布局中组织了所有内容,因此元素非常适合表行。
不幸的是,我的标题行已关闭,因此我尝试通过Rect
方法获取基础EditorGUILayout.BeginHorizontal()
来统一所有内容。
不幸的是,它会返回一个带有默认值的Rect
(一切都是0
)。所以我无法正常使用它。我错过了什么或为什么它会返回空Rect
?在EditorWindow
本身,空间已填满。
示例代码:
Rect boundary = EditorGUILayout.BeginHorizontal();
float largeWidth = boundary.width * 0.4f;
float smallWidth = boundary.width * 0.2f;
EditorGUILayout.LabelField("stuff1", GUILayout.Width(largeWidth));
EditorGUILayout.LabelField("stuff2", GUILayout.Width(largeWidth));
EditorGUILayout.LabelField("stuff3", GUILayout.Width(smallwidth));
EditorGUILayout.EndHorizontal();
答案 0 :(得分:1)
好的,所以我在网上找到了一篇博客文章,说明了显而易见的事实:
当Object没有填充时,不会填充Rect。当事件被触发而不包含信息收集时,信息将可用。
所以我最终做的是:
毕竟这是一个肮脏的解决方案,但确实有效。
以下是感兴趣的人的一些示例代码:
public class CustomWindow : EditorWindow
{
#region Private Fields
private Vector2 scrollLocation;
private float elementsWidth;
private float textBoxWidth;
private float buttonWidth;
private const int WINDOW_MIN_SIZE = 400;
private const int BORDER_SPACING = 10;
private const int ELEMENT_SPACING = 8;
#endregion Private Fields
#region Public Methods
[MenuItem("Window/CustomWindow")]
public static void ShowWindow()
{
CustomWindow window = GetWindow(typeof(CustomWindow), false, "CustomWindow") as CustomWindow;
window.Show();
window.minSize = new Vector2(WINDOW_MIN_SIZE, WINDOW_MIN_SIZE);
window.Load();
}
#endregion Public Methods
#region Private Methods
private void OnGUI()
{
elementsWidth = EditorGUIUtility.currentViewWidth - BORDER_SPACING * 2;
textBoxWidth = elementsWidth * 0.4f;
buttonWidth = elementsWidth * 0.2f;
scrollLocation = EditorGUILayout.BeginScrollView(scrollLocation);
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("stuff1", GUILayout.Width(largeWidth));
EditorGUILayout.LabelField("stuff2", GUILayout.Width(largeWidth));
EditorGUILayout.LabelField("stuff3", GUILayout.Width(smallwidth));
EditorGUILayout.EndHorizontal();
EditorGUILayout.EndScrollView();
}
#endregion Private Methods
}