Custom Material Editor - How to hide unused/disabled Properties ?

Considering the example in 4.1 package is it possible to hide added Material Inspector Properties ?

Example if texture1 is set to off I want to hide that slot visualization inside the custom inspector:

using System.Collections.Generic;using UnityEngine;
using UnityEditor;
using System.Linq;

public class CustomMatInspector : MaterialEditor {
    public override void OnInspectorGUI ()
    {
        var targetMat = target as Material;
        var keyWords = targetMat.shaderKeywords;
        var tex1 = keyWords.Contains ("TEXTURE1ON");
        var tex2 = keyWords.Contains ("TEXTURE2ON");

        var tex1Int = EditorGUILayout.Popup ("Texture 1", tex1 ? 1 : 0, new[] {"Off", "On"});
        var tex2Int = EditorGUILayout.Popup ("Texture 2", tex2 ? 1 : 0, new[] {"Off", "On"});

        var tex1After = tex1Int == 1;
        var tex2After = tex2Int == 1;

        if (tex1 != tex1After || tex2 != tex2After)
        {
            var keywords = new List<string> { tex1After ? "TEXTURE1ON" : "TEXTURE1OFF", tex2After ? "TEXTURE2ON" : "TEXTURE2OFF"};
            targetMat.shaderKeywords = keywords.ToArray ();
            EditorUtility.SetDirty (targetMat);
        }
        base.OnInspectorGUI (); // Here I draw the inspector defined by the Shader Properties

        // If tex1After == 0 ---> I want to hide that Texture Property field
        // How do I access it knowing the propertyName that it refers to ??
    }
}

I think this could be done referring to the http://docs.unity3d.com/Documentation/Components/SL-CustomMaterialEditors.html
on the part where is explained how default material editor works How the default material editor works.
But it would make code longer so it would be better setting that field property as hidden (if possible) after having drawn everything.
And the property should retain its previous value ( the Texture reference) if the texture1 was ON before.

1 Like

This might be a bit late, but I actually wrote an article awhile ago on how to do just this.
http://martinpalko.com/Tutorials/MultiCompileUnity/MultiCompileUnity.html

1 Like