I’d like to apply a custom style to the static label part of a EditorGUILayout.FloatField,
so it’s color becomes independent from the editor’s dark/light skins.
I thought of rebuilding it using a Label and a TextField but I have no idea how to reproduce
the “drag on label to change value” behavior present in the original FloatField.
It’s more of a hack than a solution but that’s what I ended up with:
float MyFloatField(string label, float value, params GUILayoutOption[] options)
{
float returnValue;
if (EditorGUIUtility.isProSkin)
{
GUILayout.BeginHorizontal(options);
GUILayout.Label(label, "floatFieldLabel");
float.TryParse(GUILayout.TextField(value.ToString(), GUILayout.Width(40)), out returnValue);
GUILayout.EndHorizontal();
}
else
{
returnValue = EditorGUILayout.FloatField(label, value, options);
}
return returnValue;
}