How to Use The PropertyTree

By using the PropertyTree class you can implement the full power of Odin’s drawing system: attributes, property resolvers, and everything else, pretty much anywhere you need it.

Using the PropertyTree is very straightforward: use one of the PropertyTree.Create methods to create an instance for your target object, and then just call the Draw() method every frame.

MyClass myObject = new MyClass();
PropertyTree myObjectTree;

void DrawSingle()
{
    if (this.myObjectTree == null)
    {
        this.myObjectTree = PropertyTree.Create(this.myObject);
    }

    this.myObjectTree.Draw(false);
}

It is important that you retain the reference to the original created tree. Do not call PropertyTree.Create every GUI call!

If you want to, then you can also create a PropertyTree for multiple targets, and edit them all at once.

MyClass[] myObjectArray = new MyClass[]{ new MyClass(), new MyClass(), new MyClass() };
PropertyTree mutliTargetTree;

void DrawMultiple()
{
    if (this.mutliTargetTree == null)
    {
        this.mutliTargetTree = PropertyTree.Create(this.myObjectArray);
    }

    this.mutliTargetTree.Draw(false);
}

Lastly, when creating the PropertyTree you have the option of inserting your own custom OdinPropertyResolverLocator and OdinAttributeProcessorLocator instances. This lets you pretty much completely customize how the PropertyTree handles properties and attributes.

MyClass myObject = new MyClass();
PropertyTree customLocatorTree;

void DrawWithCustomLocator()
{
    if(this.customLocatorTree == null)
    {
        this.customLocatorTree = PropertyTree.Create(this.myObject, new CustomAttributeProcessorLocator());
    }

    this.customLocatorTree.Draw(false);
}

public class CustomAttributeProcessorLocator : OdinAttributeProcessorLocator
{
    private static readonly CustomMinionAttributeProcessor Processor = new CustomMinionAttributeProcessor();

    public override List<OdinAttributeProcessor> GetChildProcessors(InspectorProperty parentProperty, MemberInfo member)
    {
        return new List<OdinAttributeProcessor>() { Processor };
    }

    public override List<OdinAttributeProcessor> GetSelfProcessors(InspectorProperty property)
    {
        return new List<OdinAttributeProcessor>() { Processor };
    }
}