I have a tree-structured type that is of course recursive, and I made a reader for it(my own purposes)
But I want the reader to have a custom editor I can use. I managed to make a display for the tree but since it is recursive I can make those branches inside each other over and over again.
My question is: How do I display in the editor(inspector) a recursive type without infinitely writing the code over and over again?
My types(to help answer the question)
Branch - containing a list of splits and a value
Split - containing a parent branch and a list of sub-branches
The editor is on a reader which receives a Brach reads all the values and splits and their branches and etc…
It doesn’t sound recursive… I think the word you mean is hierarchal?
There’s two problems:
the layout of the data in 2D space so it does not overlap, and also does not get massively huge with whitespace
the actual traversal of your graph at draw time in order to render all the nodes and connections
Be sure to address those two things separately or it will get very complicated.
For problem 1, initially just hardwire positions based on depth in graph and lateral spacing, or just hand-assign positions with numbers. You can get clever later.
For problem 2, have helpers that draw each type of node and each type of connection.
Finally just traverse your graph calling the appropriate helpers to present the data.
In the Choices one (which represent the split) I want a list of routes(which represent the branch) to be made, in this picture, you can see how ONE route looks like (the button called Add Main Route can add another route to the initial list of routes but I want to make it so you can add another list into the choices and so on recursively)
So it’s a custom editor that can display and allow you to edit a directed graph of these things, where each thing can be 1 of 3 possible nodes. Take a look at some tutorials for custom editors; your code would traverse your data tree and make decisions about how to render (and allow editing of) each part of the graph.