Search Unity

  1. Unity 2019.1 beta is now available.
    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. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Unity 2018.3 is now released.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Size of a scriptable object?

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

  1. ProtagonistKun

    ProtagonistKun

    Joined:
    Nov 26, 2015
    Posts:
    47
    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:
    47
    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:
    135
    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:
    521
    GUILayout.BeginScrollView
    will manage this for you.