- Home /
Custom Inspector with field like Camera culling mask
I'm currently working on a custom inspector for one of my script. I need to be able to select one or more layers (for some filters behaviour) and so I try to have a field exactly similar to the 'Culling mask' in the Camera inspector. I tried with EditorGUILayout.EnumMaskField and EditorGUILayout.MaskField without any success despite the fact is apparently the class to use... If someone has some code example or a solution to this problem he will be welcome :)
thanks in advance
Yes but the LayerField does not allow multiple selections (and propose to 'Add a Layer'). It's not what I expect :( I need to be able to select 0, 1, 2, ... or all layers like in the 'culling mask' field of the Camera Inspector
thanks
Ah I see. Seems like you'd really want to use the enum mask field so you can pass in the list of layers. What was the issue with the enum mask field?
perhaps I'm stupid but I did not found an enum corresponding to the layers... I searching in all the enum in the documentation
Yeah, I don't think there is a list exactly, but since you know the max number of layers is 32 (0 - 31 including builtin and custom), you can loop through all those numbers and use Layer$$anonymous$$ask.LayerToName(index) to get a full text list of all layers and exclude ones that have no name. If you select something from the enum, it should be represented by the layer ID from the loop. Annoying, but it should work.
Answer by irrationalistic · Jul 24, 2012 at 08:31 PM
My only other suggestion is to utilize the default drawing of the inspector for only that one field assuming it's set as a LayerMask variable. Just add the HideInInspector directive to all the public variables you want to have custom editor fields for and do all your custom drawing. Then, at the end of the ongui stuff, add the drawdefaultinspector which will draw your default inspector stuff, essentially only drawing your layer field mask using the built-in method. Also awkward, but much easier to edit.
Answer by Sgt Crapgame · Jul 25, 2012 at 01:08 AM
I implemented my inspector as you describe ([HideInInspector] + call to DrawDefaultInspector()) and it works as expected. Thank you very much
Your answer
Follow this Question
Related Questions
Updating editor GUI on button press 2 Answers
EditorGUILayout.ObjectField cannot be changed. 1 Answer
Custom Inspector - How to add functionality? 1 Answer
How could I merge 2 components' inspectors through a custom editor? 2 Answers
How can I override the default inspector editor with my own? 3 Answers