Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Question Property field array not collapsing on click

Discussion in 'Immediate Mode GUI (IMGUI)' started by puddleglum, Dec 5, 2023.

  1. puddleglum

    puddleglum

    Joined:
    May 11, 2020
    Posts:
    406
    yes i know i have to code this myself but I'm really not sure how to detect if the array field has been clicked on
    everything else works fine but the array is permanently stuck open or closed depending on what I statically set the .isexpanded value to in the script
    Code (csharp):
    1.  
    2. static void DrawArray(TargetScript _Target)
    3.     {
    4.  
    5.         var serializedObject = new SerializedObject(_Target);
    6.             var property = serializedObject.FindProperty("list");
    7.             serializedObject.Update();
    8.             EditorGUILayout.PropertyField(property, true);
    9.  
    10.             serializedObject.ApplyModifiedProperties();
    11.      
    12.  
    13.     }
    14.  
    15.  
    16.  
     
  2. lleondlg05

    lleondlg05

    Joined:
    Aug 28, 2018
    Posts:
    7
    I think that it can be usefull to you:

    https://catlikecoding.com/unity/tutorials/editor/

    the Custom List tutorial is what you need, basically, you create a EditorList script where you will define your lists,
    if they can be expanded, showing the size, showing the label...

    and then you create an inspector where will apply the "new layout" to your properties
     
    puddleglum likes this.