Search Unity

¿CustomEditor and CustomPropertyDrawe are incompatibles?

Discussion in 'Scripting' started by pleasurehouse, Mar 20, 2021.

  1. pleasurehouse

    pleasurehouse

    Joined:
    Oct 15, 2020
    Posts:
    96
    I have a Property Drawer derived class that i use for select the Layers... something like this

    Code (CSharp):
    1.  
    2. //-------------------------------------------------
    3. [CustomPropertyDrawer(typeof(LayerSelectorAttribute))]
    4. //-------------------------------------------------
    5. public class LayerSelectorPropertyDrawer : PropertyDrawer
    6. {
    7.       //some code
    8. }
    9.  
    I use it like this:

    Code (CSharp):
    1.  
    2. //------------------------------------------------------------------------
    3. [Serializable]
    4. public class DataClass
    5. {
    6.     [LayerSelector]
    7.     public string layerName;   //--> here it does works
    8.    /// more vars.....
    9. }
    10. //------------------------------------------------------------------------
    11. public class MyClass: MonoBehaviour
    12. {
    13.     public DataClass dataClass;  //--> here it does works
    14.     public bool disable;
    15. }
    16.  
    17.  
    i'm trying to do a CustomEditor now... like this..


    Code (CSharp):
    1.  
    2. [CustomEditor(typeof(MyClass))]
    3. public class MyClassEditor : Editor
    4. {
    5.     override public void OnInspectorGUI()
    6.     {
    7.             var myClass = target as MyClass;
    8.             var dataClass = this.serializedObject.FindProperty("dataClass");
    9.  
    10.             myClass.disable = GUILayout.Toggle(myClass.disable, "Disable Fields");
    11.             using (new EditorGUI.DisabledScope(tmyClass.disable))
    12.             {              
    13.                 EditorGUILayout.PropertyField(dataClass, true);       //--> here it does not  works
    14.                
    15.             }
    16.    }
    17. }
    18.  
    Ok, on this point i can see the instance name "dataClass" on the editor but nothing more... all variables of the class DataClass are missing/disapear...

    ¿Do you know if to do this is incompatible or i'm doing something wrong?

    thank you so much!!