vexe / VFW

MIT License
492 stars 67 forks source link

PerItem +Display(FormatMethod) #24

Closed ajboni closed 9 years ago

ajboni commented 9 years ago

Hello Again Vexe, I was wondering if there is any way to dynamically format an array perItem according to each Item properties. (Probably carrying an Index or the object itself) Display(FormatMethod) works great for all items, but It doesn't carry the object i think.

    [PerItem, Display(FormatMethod = "FormatArray")]
    public List<UAE_Dialogue_BaseNode> DialogList = new List<UAE_Dialogue_BaseNode>();  

    // gets called from editor
    string FormatArray(int index)
    {
        return "# " + DialogList[index] + " - " + DialogList[index].Actor.Name;
                //Example output:
                // #0 - Player
                // #1 - John
    }

or

[PerItem, Display(FormatMethod = "FormatArray")]
    public List<UAE_Dialogue_BaseNode> DialogList = new List<UAE_Dialogue_BaseNode>();  

    // gets called from editor
    string FormatArray(UAE_Dialogue_BaseNode node)
    {
        return node.Actor.Name + ":" + node.Text;
                //Example output:
                // Player: Hello
                // John: Hi
    }

Another workaround could be change the label of each instance: captura

Thanks!!

vexe commented 9 years ago

Right. Actually the first version of FormatMethod used to take an instance object, but then i saw that I'm only using it to display collection count, obviously forgetting about using it PerItem. I also need to fix the fact that the sequence should ignore Display if it's applied on its elements.

There's not much can be done about the 'instance label' in your case since they're Unity objects. If they were System objects you could override their ToString and it would show whatever you specify for that element's ToString.

ajboni commented 9 years ago

Thanks! the ToString override did the trick!! Very useful!