I have a shader with an outline feature that I want to be able to toggle on and off. Since boolean isn’t a supported property type in ShaderLab I’m using a float (as recommended). Although with a simple [MaterialToggle] attribute in front of a float-type property in shaders will show the float as a checkbox in the editor, unfortunately it doesn’t work that way when you have a custom Shader UI.
Is there a way in my custom Shader UI to have a float that displays as a boolean? Having a non-custom Shader UI is not an option for me.
That’s exactly what the original post already said, and doesn’t answer the question they had, which is how to show a toggle when using a custom shader editor. Using the material property drawer works for the default material editor, but not always for custom material editors.
Also, you just need [Toggle], the “Material” at the start is superfluous.
There’s two ways to do it.
One is using the material property drawer, then using materialEditor.ShaderProperty(prop, propDisplayName) to draw that property. It will respect the material property drawer applied to the property.
The other way is just like shown in the example code in the above link, using the generic EditorGUILayout.Toggle like any other GUI.
bool value = prop.floatValue != 0.0f;
value = EditorGUILayout.Toggle(propDisplayName, value);
prop.floatValue = value ? 1.0f : 0.0f;