Я создаю собственный ящик свойств для ScriptableObject только с двумя полями: GameObject и string.
Этот реквизит будет отрисован в инспекторе по умолчанию (кроме GUILayout.Button сверху) объекта, содержащего только один список объектов, доступных для сценариев.
Мне нужно свойство поля со строкой, чтобы быть 2 строки высоты, и я написал соответствующий код, который должен работать. Но поля все еще имеют высоту в 1 строку. Почему так? Как я могу это исправить?
Вот код:
ScriptableObject
using UnityEngine;
[System.Serializable]
public class StringDatabaseEntry {
public GameObject key;
public string value;
public StringDatabaseEntry(GameObject _key, string _value) {
value = _value;
key = _key;
}
}
propertyDrawer
using UnityEngine;
using UnityEditor;
[CustomPropertyDrawer(typeof(StringDatabaseEntry))]
public class StringDatabaseEntryDrawer : PropertyDrawer {
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
float h = EditorGUIUtility.singleLineHeight;
EditorGUI.BeginProperty(position, label, property);
int indent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;
Rect keyRect = new Rect(position.x, position.y, position.width, h);
Rect valueRect = new Rect(position.x, position.y + h, position.width, position.height - h);
EditorGUI.PropertyField(keyRect, property.FindPropertyRelative("key"), GUIContent.none);
EditorGUI.PropertyField(valueRect, property.FindPropertyRelative("value"), GUIContent.none);
// SerializedProperty prop = property.FindPropertyRelative("value");
// prop.stringValue = EditorGUI.TextField(valueRect, prop.stringValue);
EditorGUI.indentLevel = indent;
EditorGUI.EndProperty();
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
return EditorGUIUtility.singleLineHeight * 3;
}
}
Я также попытался добавить атрибут [TextArea]
к _key
, который сделал вещи еще более беспорядочными и необъяснимыми.
Здесь Inspector Screenshot
и Inspector Screenshot with [TextArea]
,
![Inspector Screenshot with [TextArea]](https://i.stack.imgur.com/Kcqb7.png)