Search Unity

How to traverse MaterialProperties for a Custom Material Inspector implementation ?

Discussion in 'Shaders' started by mayorc1978, Mar 5, 2014.

  1. mayorc1978

    mayorc1978

    Joined:
    Dec 30, 2013
    Posts:
    36
    Trying to create an Ubershader, I was trying to make a custom inspector for materials, though a few problem arose.

    When doing the custom inspector part, I tried implementing the default material inspector like written inside:
    http://docs.unity3d.com/Documentation/Components/SL-CustomMaterialEditors.html

    Precisely the part :
    Code (csharp):
    1. private void ShaderPropertyImpl(Shader shader, int propertyIndex)
    Here to traverse the properties, it does this by propertyIndex.
    Using:
    Code (csharp):
    1. ShaderUtil.GetPropertyDescription(shader, i);
    2. ShaderUtil.GetPropertyName(shader, i);
    3. ShaderUtil.GetPropertyType(shader, i);
    Then to create Controls it uses:
    Code (csharp):
    1. FloatProperty(propertyName, label);
    2. VectorProperty(propertyName, label);
    3. // And so on
    But these last are obsolete methods as it suggest to use:
    "Use FloatProperty with MaterialProperty instead" which method is signed as:
    Code (csharp):
    1. float MaterialEditor.FloatProperty(MaterialProperty prop, string label)
    I need to traverse the properties indexes and hide texture/color/float/vector properties fields.
    So how do I collect the properties and traverse them in the right order and check property names using MaterialProperty.

    Currently I check against property names based on a hide list (which contains a dynamic list to hide/show properties based on custom Toggles/Popups to remove Textures/Colors/and so on...).

    Also when some propertyName is on the hideList i simply skip that index using continue; but when I gave a look on:
    ShaderUtil ScriptReference:
    http://docs.unity3d.com/Documentation/ScriptReference/ShaderUtil.html

    I saw there is a ShaderUtil.IsShaderPropertyHidden method, but there is no description on how to use that, or on How to Hide a Property. :confused:

    Any help would be useful.
     
    Last edited: Mar 5, 2014
  2. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Bump...