Search Unity

  1. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  2. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  3. If you couldn't join the live stream, take a peek at what you missed.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  5. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  6. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  7. 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:
    820
    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:
    820
    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:
    81
    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.margin = new RectOffset( 0, 0, 4, 4 );
    5. horizontalLine.fixedHeight = 1;
    6.  
    7. // utility method
    8. static void HorizontalLine ( Color color ) {
    9.     var c = GUI.color;
    10.     GUI.color = color;
    11.     GUILayout.Box( GUIContent.none, horizontalLine );
    12.     GUI.color = c;
    13. }
    14.  
    15. // use it!
    16. GUILayout.Label( "Some content above" );
    17.  
    18. MyGUI.HorizontalLine( Color.grey );
    19.  
    20. GUILayout.Label( "Some content below" );
     
    Last edited: May 31, 2018
    echologin likes this.
  5. StylishCoding

    StylishCoding

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

    alexanderameye

    Joined:
    Nov 27, 2013
    Posts:
    675
    echologin likes this.