Skip to content

Virtual Methods

OnInitialize

Description

Called once when initializing PropertyPainter.

Very useful for make some initializations of properties and get view attribute.

void OnInitialize(SerializedProperty property, PainterAttribute painterAttribute, GUIContent label)
{
    // Some initialization...
}

Parameters

Parameter Description
property Serialized property with ViewAttribute.
painterAttribute PainterAttribute of serialized property.
label Label of serialized property.

Example

[PainterTarget(typeof(ExampleAttribute))]
public class ExampleView : PropertyPainter
{
    private ExampleAttribute exampleAttribute;

    // Called once when initializing PropertyPainter.
    public override void OnInitialize(SerializedProperty property, PainterAttribute painterAttribute, GUIContent label)
    {
        // Getting ExampleAttribute attribute from field.
        exampleAttribute = painterAttribute as ExampleAttribute;

        // Some other initializations here...
    }
}

ModifyPropertyPosition

Description

Called before OnPainterGUI() for modify property position.

void ModifyPropertyPosition(Rect originalPosition, ref Rect modifiedPosition)
{
    // Modify property position here.
}

Parameters

Parameter Description
originalPosition Stored original position of the property.
modifiedPosition Current position which has been modified by other painters, if this property contains other painter attributes.

Example

[PainterTarget(typeof(ExampleAttribute))]
public class ExampleView : PropertyPainter
{
    // Called before OnPainterGUI() for modify property position.
    public override void ModifyPropertyPosition(Rect originalPosition, ref Rect modifiedPosition)
    {
        const float offset = 5.0f;
        modifiedPosition.x += offset;
        modifiedPosition.width -= offset;
    }
}

OnPainterGUI

Description

Called for rendering and handling GUI events.

void OnPainterGUI(Rect originalPosition, Rect painterPosition, SerializedProperty property, GUIContent label)
{
    // Painter GUI here...
}

Parameters

Parameter Description
originalPosition Stored original position of the property.
painterPosition Rectangle on the screen to use for the painter GUI.
property Serialized property with PainterAttribute.
label Label of serialized property.

Example

[PainterTarget(typeof(ExampleAttribute))]
public class ExampleView : PropertyPainter
{
    // Called for rendering and handling GUI events.
    public override void OnPainterGUI(Rect originalPosition, Rect painterPosition, SerializedProperty property, GUIContent label)
    {
        GUI.Label(painterPosition, "Custom property painter");
    }
}

GetPainterHeight

Description

Get the height of the painter, which required to display it.

Calculate only the size of the current painter, not the entire property.

The painter height will be added to the total size of the property with other painters.

// Return height which needed to draw painter.
float GetPainterHeight(SerializedProperty property, GUIContent label)
{
    // Return height of painter.
}

Parameters

Parameter Description
property Serialized property with ViewAttribute.
label Label of serialized property.

Example

[PainterTarget(typeof(ExampleAttribute))]
public class ExampleView : PropertyPainter
{
    // Return height which needed to draw painter.
    public virtual float GetPainterHeight(SerializedProperty property, GUIContent label)
    {
        return 20;
    }
}