Unity Community

Register or Sign In:

+ Reply to Thread
Results 1 to 4 of 4

  1. Posts
    74

    OnGUIInspector default drawing

    I'm writing a custom inspector for a component, and I want to override "most" of the visible properties of the component; however, there are a couple of the properties that Id' really like to be rendered out using the default method DrawDefaultInspector().

    While I know this method is an all or nothing, I would like to be able to utilize its standard view for an array of objects that I have. The standard inspector for arrays works fine for adding/removing from the list, drag and drop, etc. I'd hate to have to rewrite a version of that if I could just use the built-in renderer.

    Looking at the EditorGUILayout methods and EditorGUI methods, I don't see anything like a "EditorGUILayout.ArrayField" or something. Does such a thing exist, or is there a way to get the standard array inspector GUI to show up in the inspector window without having to hide every property but that one array via attributes?

    Thanks for any insight.


  2. Location
    Phoenix, AZ
    Posts
    83
    I'm also wondering this same thing. I would really like to expose just a single array on my object to the editor, not all the public fields with DrawDefaultInspector but I don't see anything that lets you just expose a single array. This is an array of primitive objects so there is no issue with the serialization.


  3. Location
    Yesterday
    Posts
    664
    You can use @HideInInspector just before a var that you want to overwrite the Inspector for.

    That is:

    Code:  
    1. var anArray : GameObject[];
    2.  
    3. @HideInInspector
    4. var customInspectorVar : float;

    Then the inspector won't show customInspectorVar. You can then use DefaultInspector, and add your code to inspect the customInspectorVar after that.

  4. ReJ ReJ is offline

    Location
    Unity Technologies
    Posts
    353
    Try this code for displaying SerializedProperty of Array type in custom inspector:

    Code:  
    1.     static public void ArrayField (SerializedProperty property)
    2.     {
    3.         bool wasEnabled = GUI.enabled;
    4.         int prevIdentLevel = EditorGUI.indentLevel;
    5.        
    6.         // Iterate over all child properties of array
    7.         bool childrenAreExpanded = true;
    8.         int propertyStartingDepth = property.depth;
    9.         while (property.NextVisible(childrenAreExpanded) && propertyStartingDepth < property.depth)
    10.         {
    11.             childrenAreExpanded = EditorGUILayout.PropertyField(property);
    12.         }
    13.        
    14.         EditorGUI.indentLevel = prevIdentLevel;
    15.         GUI.enabled = wasEnabled;
    16.     }

    Now part of EditorGUIExtension on UnifyCommunity: http://www.unifycommunity.com/wiki/i...orGUIExtension
    Last edited by ReJ; 06-17-2011 at 09:21 AM.