Posted February 07, 2021 by BigHandInSky
TL;DR: I've made a struct & propertyDrawer to dynamically create a dropdown menu to pick any knot from your assets folder.
~~~
Hey folks, so got another useful bit of editor code to share, this one is here to deal with a common problem in the project:
Now the best way to deal with this is to just list a dropdown of all the possible options you can pick... which is actually fairly straightforward!
Previously in the project I already made this little tool to help with testing a story in the story-player scene. So I already had the actual search code ready, next up was making the property drawer itself. A catch I ran into with the drawer though: you kind of need to side-step setting the serialisedProperty directly, instead setting a local string, then setting the string afterwards. (This is because the Menu dropdown is technically happening after `OnGUI(...)` finishes, so you've got some kind of Async thing going on)
~~~
For reference if you want to learn how this was put together, here are the various strands to research:
Because this happens in edit-time, I find you can afford to do some proper file-crawls like this, however once this scales up to 100s of ink files you'd want to avoid a crawl every time you click on a dropdown. That's why it uses a static dictionary. There may be other optimisations to add, but this is a first implementation.