0
我有兩個整數屬性,並希望在一行中顯示它們。以水平,愉快的方式顯示屬性
[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();
}
}
所以我想刪除一個標籤和輸入框之間那些大的空間,並添加屬性之間的一些空間。
聽說物業抽屜能幫助我,所以我想它
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();
}
}
但它不動的輸入域更接近相應的標籤,我只能改變輸入欄的寬度。
如何刪除標籤和輸入字段之間的空間,並在不同屬性之間添加空格?