Get MaterialPropertyDrawers for custom editor

I’m currently working on a custom editor which requires me to print out material fields in a certain fashion.

For this I can use ShaderUtil to handle the parsing of properties, their types, etc.

However, I cannot seem to find anything to figure out if a propery might have any MaterialPropertyDrawers (like [MaterialToggle] on a float, which default inspector will then turn into a checkbox).

Am I missing something, or is it simply not exposed/supported?

Fixed it myself, Unity hasn’t exposed this behavior yet, probably due to its experimental nature. However, if you are really dieing to get access to it, here’s a small class with some Reflection magic.

public static class ShaderUtilExtensions
{
    private delegate string GetShaderPropertyAttributeDelegate(Shader s, string name);
    private static GetShaderPropertyAttributeDelegate _getShaderPropertyAttribute;

    public static string GetShaderPropertyAttribute(Shader s, string name)
    {
        if (_getShaderPropertyAttribute == null)
        {
            Type type = typeof (ShaderUtil);
            MethodInfo methodInfo = type.GetMethod("GetShaderPropertyAttribute", BindingFlags.Static | BindingFlags.NonPublic);

            _getShaderPropertyAttribute = (GetShaderPropertyAttributeDelegate)Delegate.CreateDelegate(typeof(GetShaderPropertyAttributeDelegate), methodInfo);
        }

        return _getShaderPropertyAttribute(s, name);
    }
}

Not going to explain what it does in detail however: With reflection I search for the method “GetShaderPropertyAttribute”, assuming I find it, I create a delegate to it and store that in the static variable so it only happens once in the lifetime of the current Unity Editor instance. The reason I do this, rather than “Invoke” on the MethodInfo is because a delegate results in pretty much native calling speeds.