Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Horizontal objects not drawing correctly

Discussion in 'Extensions & OnGUI' started by ProtagonistKun, Dec 6, 2018.

  1. ProtagonistKun

    ProtagonistKun

    Joined:
    Nov 26, 2015
    Posts:
    38
    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:
    38
    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