In need of a way to display a color without the color picker field, as it is simply for display purposes only and the developer won’t be editing the color,
Is there a way to alter the EditorGUILayout.ColorField so that is read only, or does anybody know of another way around this.
I would create a CustomPropertyDrawer and PropertyAttribute for your field, then, in the drawer, draw a white box tinted with the properties colorValue:
e.g:
class MyClass : MonoBehaviour {
[ReadonlyColor]
public Color myColor;
}
class ReadonlyColorAttribute : PropertyAttribute {
}
[CustomPropertyDrawer(typeof(ReadonlyColorAttribute))]
class ReadonlyColorDrawer : PropertyDrawer {
public override OnGUI(Rect position, SerializedProperty property, GUIContent label) {
if (property.propertyType == SerializedPropertyType.Color) {
Color guiColor = GUI.color;
GUI.color = property.colorValue;
GUI.DrawTexture(position, EditorGUIUtility.whiteTexture);
GUI.color = guiColor;
}
else {
EditorGUI.PropertyField(position, property, label);
}
}
}