- Home /
How to create bitmask flags per scene that are available in the editor?
Hello! My current project is a 3D anatomy exploration app that will show labeled parts of the human anatomy. Clicking on a label turns off rendering of all parts outside the selected region, zooms in and rotates the model to give a better view of the selected region, and exposes subregions of the selected region for further exploration. For example, at the top level you'd have head, arm, torso, leg, etc. If you select the arm label, you'd get shoulder, upper arm, forearm, hand.
To facilitate this functionality I first implemented a solution using enum flags as explained in these threads:
http://answers.unity3d.com/questions/486694/default-editor-enum-as-flags-.html
http://answers.unity3d.com/questions/393992/custom-inspector-multi-select-enum-dropdown.html
I'd like to use flags because a particular part can be visible for more than one region. However, after setting up part of the arm I realized this solution would limit me to 32 total regions and I'll likely need far more than that for the entire body. Additionally, we're planning on having small "story" scenes that step through small sections of the anatomy and explain their relation to each other. These scenes will likely need to define their own regions rather than use the ones I've set up for the full body. I realize I could instead switch to a long enum, but that seems like a band-aid fix and it doesn't solve the problem with the story scenes having to deal with all of the regions of the body.
What I'd like to do is switch the enum flags to an array of bools where each entry in the array corresponds to an anatomy region. The problem with this is I'm not sure how to force each bool array on each object in the scene to have the same length. Furthermore, I'm not sure how to set up a custom editor script so the labels on each entry in the array correspond to predefined region names in that scene. I tried using an array of strings on a singleton object in the scene, but that doesn't work because the singleton object isn't active available in the editor.
After doing a bit of digging it looks like ScriptableObjects might help me out here, but I'm not sure how to make them available to a custom Editor or PropertyDrawer script. I'm also not sure how to force the same length on every bit array in the scene.
After typing all of this out it has occurred to me that I could simply continue to use enums, but switch to a list and simply check if an object's region enum list contains the active region. However I'd still like to know if there's a way to dynamically rename things in the editor through a ScriptableObject rather than hardcoding the name into my editor script!
Your answer
Follow this Question
Related Questions
Custom editor not editing? 1 Answer
Custom editor tags not saving 1 Answer
Draw inspector of array elements? 1 Answer
Trouble setting the object reference in a property drawer 0 Answers