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. Nominations have been announced for this years Unity Awards. Celebrate the wonderful projects made by your peers this year and get voting! Vote here!
    Dismiss Notice
  6. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  7. 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:
    38
    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:
    38
    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