- Home /
How do I create a check-able list of terrain textures in the Inspector?
I am creating a script that will only place objects on the terrain that have a specific texture assigned based on selections from a terrain texture list.
What I need is a 'check-able' list of terrain textures in the inspector similar to the Camera Culling Mask list shown below (e.g. Anywhere or just on the selected textures ).

I know how to get the terrain texture index (and other texture information) at any given point on the active terrain. I'm just trying to make the inspector interface easier to use than simply adding a delimited list of numbers (e.g. 0,3,5) and hoping users get them right. It would be nice to show a thumbnail of the texture (like in the Terrain editor) but I don't want to take up too much real-estate.
Anybody have any ideas, suggestions, and/or code?
Assu$$anonymous$$g you have a custom editor already, check out https://docs.unity3d.com/ScriptReference/EditorGUILayout.$$anonymous$$askField.html
The only problem I see with using EditorGUILayout.$$anonymous$$askField or EditorGUILayout.Enum$$anonymous$$askField is that I need the list to be dynamic in nature. That is, like the 'Culling $$anonymous$$ask' ... when new layers are added the list displays them automatically. $$anonymous$$ine needs to do the same as new textures are added.
I guess that $$anonymous$$askField is the way to go as it has an array that I can stuff with the texture details. Question is, where does this code go ... in the Editor code I assume. Next question is how to update this array when textures are added.
Always something new to figure out ;)
Every time you call $$anonymous$$askField you will need to pass in the array of strings that can be selected. If that list changes from one editor update to the next, the displayed options will change. The tricky part is going to be dissecting the returned mask field to see which ones are checked. (you'll want to use bitwise "AND" operator and the shiftright ">>" operator, to loop through all the bits.)
Yes, you would add the EditorGUILayout function to a "Custom Editor" for the $$anonymous$$onobehavior object that contains it.
Not sure how you add textures, so can't address that.
Your answer
Follow this Question
Related Questions
EditorGUI add SortingLayer-like list to custom Editor 1 Answer
Custom Editor problems 2 Answers
Create inspector drop-down button based on the content of a list in editor mode 1 Answer
Is it possible to drag/drop/increment into editor array? 1 Answer
Unity Editor Inspector creating gameObjects in world 2 Answers