我有两个整数属性,想在一行中显示它们。
[CustomEditor(typeof(MazeConfiguration))]
public class MazeConfigurationEditor : Editor
{
MazeConfiguration myTarget;
public void OnEnable()
{
myTarget = (MazeConfiguration)target;
}
public override void OnInspectorGUI()
{
EditorGUILayout.BeginHorizontal();
myTarget.Width = EditorGUILayout.IntField("Width", myTarget.Width);
myTarget.Length = EditorGUILayout.IntField("Length", myTarget.Length);
EditorGUILayout.EndHorizontal();
}
}
所以我想删除标签与其输入字段之间的那些大空格,并在属性之间添加一些空格。
听说Property Drawer可以帮到我所以我试了一下
public class MyIntAttribute : PropertyAttribute { }
[CustomPropertyDrawer(typeof(MyIntAttribute))]
public class MyIntDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
// position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
var rect = new Rect(position.x / 2f, position.y, position.width / 2f, position.height);
EditorGUI.PropertyField(rect, property);
EditorGUI.EndProperty();
}
}
但它不会将输入字段移动到更靠近相应标签的位置,我只能更改输入字段的宽度。
如何删除标签和输入字段之间的空格,并在不同属性之间添加空格?