Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Horizontal objects not drawing correctly

Discussion in 'Immediate Mode GUI (IMGUI)' started by ProtagonistKun, Dec 6, 2018.

  1. ProtagonistKun

    ProtagonistKun

    Joined:
    Nov 26, 2015
    Posts:
    174
    So I was asked to make a script to compare certain object and have found this code works, however only when I draw the editors vertical do I see everything. When I draw it horizontal (like it should be for this case) part of the data is not visible. It seems to be an issue with subclassing of the data I think. Both the RenderData variable and InfoDataHandler are drawing as empty (the space is occupied, but with spaces)

    Data structure:
    Code (CSharp):
    1. public class FabricObject{
    2. public string DisplayName { get { return InfoDataHandler.GetString(InfoDataKeys.NAME); } set { InfoDataHandler.SetString(InfoDataKeys.NAME, value); } }
    3.         public Sprite Icon;
    4.         [Header("Textures")]
    5.         public FabricData RenderData;
    6.  
    7.         [SerializeField]
    8.         public InfoDataHandler InfoDataHandler = new InfoDataHandler();
    9. }

    Editor window code:
    Code (CSharp):
    1. public class FabricComparer : EditorWindow
    2. {
    3.     private static List<FabricObject> fabrics = new List<FabricObject>();
    4.  
    5.     private Vector2 scrollPos;
    6.  
    7.     public static void Open(List<string> list)
    8.     {
    9.         if (list.Count > 0)
    10.         {
    11.             foreach (var fabric in list)
    12.             {
    13.                 var fab = AssetDatabase.LoadAssetAtPath<FabricObject>(fabric);
    14.                 if (fab)
    15.                 {
    16.                     fabrics.Add(fab);
    17.                 }
    18.             }
    19.         }
    20.  
    21.         var window = GetWindow<FabricComparer>("Fabric comparer");
    22.     }
    23.  
    24.     void OnGUI()
    25.     {
    26.         scrollPos = GUILayout.BeginScrollView(scrollPos);
    27.         GUILayout.BeginHorizontal();
    28.         foreach (var fabric in fabrics)
    29.         {
    30.             GUILayout.BeginVertical();
    31.             Editor.CreateEditor(fabric).OnInspectorGUI();
    32.             GUILayout.EndVertical();
    33.             GUILayout.Space(10);
    34.         }
    35.         GUILayout.EndHorizontal();;
    36.         GUILayout.EndScrollView();
    37.     }
    38. }
     
    Last edited: Dec 6, 2018
  2. ProtagonistKun

    ProtagonistKun

    Joined:
    Nov 26, 2015
    Posts:
    174
    I found a way to do it by putting the data inside the scrollrect inside of an area, that seems to get around the issue