【发布时间】:2017-08-10 06:07:27
【问题描述】:
我目前正在开发我的编辑器扩展,并决定使用图像添加自定义按钮,然后使用水平布局组将其与文本字段放在同一行
很遗憾,文本字段不再与中心对齐。
这是有问题的代码
//Displays absolute root path
EditorGUILayout.SelectableLabel("Root Directory: " + RootPath, EditorStyles.miniLabel, GUILayout.MaxHeight(16));
//Creates BuildPath
DesiredPathType = (PathType)EditorGUILayout.EnumPopup(new GUIContent("Path Type"), DesiredPathType);
//BuildName TextField
BuildName = EditorGUILayout.TextField(new GUIContent("Build Name"), BuildName);
//OutputPath directory selector
GUILayout.BeginHorizontal();
GUIStyle Style = EditorStyles.textField;
Style.alignment = TextAnchor.UpperLeft;
OutputPath = EditorGUILayout.TextField(new GUIContent("Output Path"), OutputPath, Style);
Style = GUIStyle.none;
Style.padding = new RectOffset(0, 0, 2, 0);
GUILayout.Button(new GUIContent(FolderIcon), Style, GUILayout.MaxHeight(16), GUILayout.MaxWidth(19));
GUILayout.EndHorizontal();
//SubFolders toggle
Subfolders = EditorGUILayout.Toggle(new GUIContent("Subfolder per Platform"), Subfolders);
具体来说,这部分
//OutputPath directory selector
GUILayout.BeginHorizontal();
GUIStyle Style = EditorStyles.textField;
Style.alignment = TextAnchor.UpperLeft;
OutputPath = EditorGUILayout.TextField(new GUIContent("Output Path"), OutputPath, Style);
Style = GUIStyle.none;
Style.padding = new RectOffset(0, 0, 2, 0);
GUILayout.Button(new GUIContent(FolderIcon), Style, GUILayout.MaxHeight(16), GUILayout.MaxWidth(19));
GUILayout.EndHorizontal();
文件夹图标图片
【问题讨论】:
-
文本字段停止与中心对齐?预期的外观是什么?也许你可以给我们看一张草图。
-
在左侧添加问题,在右侧添加问题
-
我仍然无法弄清楚问题所在。左右唯一的区别是
FolderIcon的存在感。 -
放大并仔细观察;右侧的输出路径文本字段在其上方和下方的 GUI 元素之间完美居中,而在左侧,整个内容略微太低
-
哦,我明白了。
标签: c# user-interface unity3d editor