Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Noob ProbertyDrawer question

Discussion in 'Immediate Mode GUI (IMGUI)' started by RoughSpaghetti3211, Mar 30, 2017.

  1. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,697
    Hello,
    Ive just grabbed an example from the web and playing with it to learn about Property Drawer.
    Just wondering if someone could inform me why I get a little side scroll on int arrays when I place it under an existing array. If you look at the image you can see the difference between the two. How can I kill it !!


    Screen Shot 2017-03-30 at 6.37.49 AM.png

    Code (CSharp):
    1.  
    2. [CustomPropertyDrawer(typeof(GridData), true)]
    3. public class GridDataPropertyDrawer : PropertyDrawer {
    4.  
    5.  
    6.     public override void OnGUI(Rect position,SerializedProperty property,GUIContent label){
    7.         EditorGUI.PrefixLabel(position,label);
    8.         Rect newposition = position;
    9.         newposition.y +=  EditorGUIUtility.singleLineHeight;
    10.         SerializedProperty data = property.FindPropertyRelative("rows");
    11.         //data.rows[0][]
    12.         for(int j=0;j<GridData.numRows;j++){
    13.             SerializedProperty row = data.GetArrayElementAtIndex(j).FindPropertyRelative("colum");
    14.             newposition.height =  EditorGUIUtility.singleLineHeight;
    15.             if(row.arraySize != GridData.numColums)
    16.                 row.arraySize = GridData.numColums;
    17.             newposition.width = position.width/GridData.numColums ;
    18.             for(int i=0;i<GridData.numColums;i++){
    19.                 EditorGUI.PropertyField(newposition,row.GetArrayElementAtIndex(i),GUIContent.none);
    20.                 newposition.x += newposition.width;
    21.             }
    22.  
    23.             newposition.x = position.x;
    24.             newposition.y +=  EditorGUIUtility.singleLineHeight;
    25.         }
    26.     }
    27.  
    28.     public override float GetPropertyHeight(SerializedProperty property,GUIContent label){
    29.         return  EditorGUIUtility.singleLineHeight * GridData.numRows +  EditorGUIUtility.singleLineHeight;
    30.     }
    31. }
    32.  
     
  2. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,307
    Try

    Code (CSharp):
    1. EditorGUI.indentLevel--;
    2. for(int i=0;i<GridData.numColums;i++){
    3.                 EditorGUI.PropertyField(newposition,row.GetArrayElementAtIndex(i),GUIContent.none);
    4.                 newposition.x += newposition.width;
    5. }
    6. EditorGUI.indentLevel++