Question by
Brantkings · Dec 16, 2016 at 03:49 PM ·
prefabcustom editorpropertydrawercustom inspectorproperty drawer
Property drawer with multiple fields: only first field has prefab override implemented
Hey guys:
I've been trying to just make a custom property drawer for a serializeable class with multiple fields. It works fine, the problem is just when I try use it on a prefab and I try to override some (not all) of it's values on a instance. The label simply does not go bold, indicating that it is overriding over the prefab.
When I change the enemy_alert AudioClip value, the property label get bold. It doesn't when I change the enum or the bool.
Am I doing something wrong?
Here's my code:
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
int indent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;
SerializedProperty sound = property.FindPropertyRelative("sound");
SerializedProperty source = property.FindPropertyRelative("source");
SerializedProperty hasMoreSounds = property.FindPropertyRelative("moreSounds");
SerializedProperty randomSounds = property.FindPropertyRelative("sfxRandomSounds");
Rect col = position;
col.width = position.width * 0.7f;
Rect soundRect = col;
EditorGUI.PropertyField(soundRect, sound, label);
col.x += col.width;
col.width = position.width * 0.3f - 10f;
EditorGUI.PropertyField(col, source, GUIContent.none);
col.x += col.width;
col.width = position.width * 0.1f;
EditorGUI.PropertyField(col, hasMoreSounds, GUIContent.none);
if (hasMoreSounds.boolValue)
{
EditorGUI.indentLevel++;
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(randomSounds, true);
if (EditorGUI.EndChangeCheck())
property.serializedObject.ApplyModifiedProperties();
EditorGUI.indentLevel--;
}
EditorGUI.indentLevel = indent;
EditorGUI.EndProperty();
}
unityaskproperty.png
(41.0 kB)
Comment
Answer by ModLunar · Jun 08, 2018 at 03:37 AM
I actually was just looking this up myself, someone found out how it works here! https://answers.unity.com/questions/62455/how-do-i-make-fields-in-the-inspector-go-bold-when.html