Search Unity

Complex selectable element

Discussion in 'UI Toolkit' started by rogerdv, Aug 23, 2019.

  1. rogerdv

    rogerdv

    Joined:
    Jul 16, 2012
    Posts:
    90
    Im working on a dialog editor for an RPG project, and I want to display in a window the dialog nodes, and edit them in the inspector panel,a bit like Mecanim. How can I make an element composed of other elements like labels and buttons, that when clicked modifies the inspector panel, adding to it the editable elements?
     
  2. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    Easiest is to back each of your nodes/complex elements with ScriptableObjects. That way, when you click on an element, you can use the "Selection.activeObject" API to select your object. This will refresh the main Inspector window to show the UI for your object.

    But just to confirm, you're talking about UIElements elements, like VisualElement. That is, you're not using GUILayout or EditorGUILayout.
     
  3. rogerdv

    rogerdv

    Joined:
    Jul 16, 2012
    Posts:
    90
    Yes, Im talking about VisualElements.
    The problem is that the whole dialog is stored in an ScriptableObject. Would be too hard to manage if each node is a separate object, because one dialog could have dozens of nodes. Think about Fallout 2, for example.
     
  4. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    I see. Then if you want to reuse the main Unity Inspector window, you'll have to start with a custom inspector for your main ScriptableObject (for the whole graph) and manage via callbacks on the ScriptableObject itself "node selection". When a different node is selected, you replace the contents of your custom inspector with new contents (ideally by loading a different UXML). Still, you'll have to manage the bindings all yourself. You'll get no help from the bindings system.

    Worth still considering splitting your graph into individual ScriptableObjects (per node), with one ScriptableObject that just references the others. VisualScription (made to support many nodes) does the same thing. It would make selection/inspector/bindings/serialization to disk trivial.
     
  5. rogerdv

    rogerdv

    Joined:
    Jul 16, 2012
    Posts:
    90
    Im thinking about your proposal. Maybe I can organize the dialogs using folders and split nodes in separate objects.