Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. 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
  8. 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:
    830
    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:
    830
    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:
    308
    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:
    94
    echologin likes this.
  6. alexanderameye

    alexanderameye

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