Search Unity

UIElements Editors and multi-editing?

Discussion in 'UI Toolkit' started by fherbst, Jan 9, 2020.

  1. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    802
    In IMGUI, building great multi-edit editor workflows was super easy.
    You literally just have an "if (one thing targeted) and else (many things targeted)" and write specific stuff for that.

    With the new, ahead-of-time workflow, I'm not sure how to approach this. Should I set up the VisualElements double (once for single-edit, once for the specific multi-edit functionality), and then hide/unhide elements accordingly? How do I react to selection changes, are there events for that?

    Common usecase: you have a custom editor inspector button ("Modify Object"). Once you enable multi-editing you want that to read ("Modify 10 objects") and do something different.
    Additionally, often I want to display information per selected object, so I'd actually need to construct the UI differently on each selection.

    EDIT: after trying what happens I think I had a wrong "mental model" of how UIElements actually works; seems the CreateInspectorGUI is still called everytime selection changes and thus I can construct totally different UIs depending on selection as before. I thought CreateInspectorGUI was somehow only called once, but now I understand it's called once per selection change.
     
    Last edited: Jan 9, 2020
    uDamian likes this.