Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    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. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Horizontal Line in Editor Window

Discussion in 'Extensions & OnGUI' started by echologin, Mar 7, 2018.

  1. echologin

    echologin

    Joined:
    Apr 11, 2010
    Posts:
    886
    How do you make Horizontal lines like in Unity's lighting window in an EditorWindow
    I found a few ways by searching but none look as good as the lighting window

    Screen Shot 2018-03-07 at 2.26.17 PM copy.png
     
  2. echologin

    echologin

    Joined:
    Apr 11, 2010
    Posts:
    886
    Well I found a solution if anyone has a better idea Im all ears



    //============================================================
    void GuiLine( int i_height = 1 )
    {
    Rect rect = EditorGUILayout.GetControlRect(false, i_height );
    rect.height = i_height;
    EditorGUI.DrawRect(rect, new Color ( 0.5f,0.5f,0.5f, 1 ) );
    }
     
  3. Knarhoi

    Knarhoi

    Joined:
    Apr 11, 2015
    Posts:
    7
    echologin likes this.
  4. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    450
    I'm in favor of the GUIStyle method. Plays well with layouts and is highly configurable (adjusting margins or width is all done at the style level).

    Code (CSharp):
    1. // create your style
    2. GUIStyle horizontalLine;
    3. horizontalLine = new GUIStyle();
    4. horizontalLine.normal.background = EditorGUIUtility.whiteTexture;
    5. horizontalLine.margin = new RectOffset( 0, 0, 4, 4 );
    6. horizontalLine.fixedHeight = 1;
    7.  
    8. // utility method
    9. static void HorizontalLine ( Color color ) {
    10.     var c = GUI.color;
    11.     GUI.color = color;
    12.     GUILayout.Box( GUIContent.none, horizontalLine );
    13.     GUI.color = c;
    14. }
    15.  
    16. // use it!
    17. GUILayout.Label( "Some content above" );
    18.  
    19. MyGUI.HorizontalLine( Color.grey );
    20.  
    21. GUILayout.Label( "Some content below" );
     
    Last edited: May 31, 2018
    echologin likes this.
  5. StylishCoding

    StylishCoding

    Joined:
    Apr 21, 2018
    Posts:
    106
    echologin likes this.
  6. alexanderameye

    alexanderameye

    Joined:
    Nov 27, 2013
    Posts:
    720
    @echologin I use this for my editor windows.

    Code (CSharp):
    1. public static void DrawUILine(Color color, int thickness = 2, int padding = 10)
    2. {
    3.     Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(padding+thickness));
    4.     r.height = thickness;
    5.     r.y+=padding/2;
    6.     r.x-=2;
    7.     r.width +=6;
    8.     EditorGUI.DrawRect(r, color);
    9. }
    It looks pretty good.

     
    echologin likes this.