Search Unity

Size of a scriptable object?

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

  1. ProtagonistKun

    ProtagonistKun

    Joined:
    Nov 26, 2015
    Posts:
    352
    I have an object I am trying to drawin a custom editor window, which is all good and well, but it needs to be inside a scrollview. How can I get the dimensions (aka Rect) of this object? Is there a function that gives me the rect of this, or do I have to manually keep track of how big it is?
    Code (CSharp):
    1.         scrollPos = GUI.BeginScrollView(
    2.             new Rect(0, 0, position.width, position.height),
    3.             scrollPos,
    4.             new Rect(0,0, rectDimensions.x * fabrics.Count , position.height));
    5.  
    6.         for (int i = 0; i < fabrics.Count; i++)
    7.         {
    8.             FabricObject fabric = fabrics[i];
    9.  
    10.             rectDimensions.y = position.height;
    11.             GUILayout.BeginArea(new Rect((rectDimensions.x + offset) * i, 0,
    12.                 rectDimensions.x, position.height));
    13.             Editor.CreateEditor(fabric).OnInspectorGUI();
    14.             GUILayout.EndArea();
    15.         }
    16.         GUILayout.EndScrollView();
     
  2. ProtagonistKun

    ProtagonistKun

    Joined:
    Nov 26, 2015
    Posts:
    352
    I got around it by drawing a label with GUILayout and using GetLastRect() to use its y-position as the max value of the drawn OnInspectorGUI(). Can someone tell me if there is a better approach because this seems weird and unnatural
     
  3. MrMatthias

    MrMatthias

    Joined:
    Sep 18, 2012
    Posts:
    191
    I don't think there is a better way. when you create a custom inspector or property drawer you only implement OnGUI, so there is no way to tell unless you actually draw it.
     
  4. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    1,317
    GUILayout.BeginScrollView
    will manage this for you.