Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Custom Material Editor

Discussion in 'Documentation' started by MaT227, Jul 9, 2014.

  1. MaT227

    MaT227

    Joined:
    Jul 3, 2012
    Posts:
    628
    I am trying to reproduce the build-in Material Editor GUI for one of my material and add some other data. I tried to use the one given in the Custom Material Editors Manual. Unfortunately it doesn't look like the default Material Editor.

    Here is the result with the Default and the Custom Material Editor.


    Here is the problematic part of code I think.
    Code (CSharp):
    1.  
    2. float controlSize = 64;
    3. EditorGUIUtility.LookLikeControls(Screen.width - controlSize - 20);
    4.  
     
  2. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Hi,
    The example posted on http://docs.unity3d.com/Manual/SL-CustomMaterialEditors.html at "How the default material editor works" section uses obsolete calls :

    Assets/Editor/CustomMatInspector.cs(22,25): warning CS0618: `UnityEditor.MaterialEditor.RangeProperty(string, string, float, float)' is obsolete: `Use RangeProperty with MaterialProperty instead.'
    Assets/Editor/CustomMatInspector.cs(29,25): warning CS0618: `UnityEditor.MaterialEditor.FloatProperty(string, string)' is obsolete: `Use FloatProperty with MaterialProperty instead.'
    ...and 4 more.

    I can find no example on how to use the MaterialProperty and it is quite unfortunate because I will release soon a new set of toon shaders that could benefit from this feature.
     
  3. BrianMacIntosh

    BrianMacIntosh

    Joined:
    Jul 23, 2013
    Posts:
    2
    Just stumbled across this and found the solution (at least to the overlapping texture fields). You need to replace the deprecated LookLikeControls code with this:

    Code (csharp):
    1. float controlSize = 64;
    2. EditorGUIUtility.fieldWidth = controlSize;
    3. EditorGUIUtility.labelWidth = Screen.width - controlSize - 20;
     
  4. mholub

    mholub

    Joined:
    Oct 3, 2012
    Posts:
    123