Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
8
Question by Veehmot · Feb 12, 2012 at 09:15 PM · editoreditor-scriptingeditorwindoweditorgui

Horizontal Line

Is there a way to draw an horizontal line using EditorGUI / EditorGUILayout?

alt text

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image unluckyBastard · Feb 12, 2012 at 09:20 PM 0
Share

As in a seperator?

avatar image Veehmot · Feb 12, 2012 at 09:21 PM 0
Share

Yes, as in a separator.

avatar image unluckyBastard · Feb 12, 2012 at 09:22 PM 0
Share

EditorGUILayout.Seperator(); try that

avatar image Veehmot · Feb 12, 2012 at 09:24 PM 3
Share

That's behaves exactly like EditorGUILayout.Space()

avatar image dude4004 Veehmot · May 25, 2016 at 07:21 PM 0
Share

It worked for me! that little extra space is just fine!

12 Replies

· Add your reply
  • Sort: 
avatar image
44
Best Answer

Answer by sirjoan620 · Jan 12, 2017 at 01:32 PM

Simple and better solution:

         EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);


alt text


Update 20.01.2020: Also you can use NaughtyAttributes' updated version(v2.0.0). That library has an HorizontalLine attribute like in the example.

alt text


screenshot-2.png (3.3 kB)
Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image IgorAherne · May 10, 2017 at 06:40 PM 0
Share

should have been the answer

avatar image jandd661 · Aug 02, 2017 at 08:34 PM 0
Share

I found this to be the best answer for my needs. +1

avatar image SweatyChair · Oct 18, 2017 at 09:22 AM 0
Share

Best and nicest answer with image!

avatar image tactileunity05 · Apr 08, 2019 at 12:56 PM 0
Share

Do you have something similarly simple for a vertical line?

avatar image
11

Answer by Glurth · Sep 30, 2015 at 05:16 AM

I like using EditorGUILayout, this worked well...

 EditorGUILayout.TextArea("",GUI.skin.horizontalSlider);
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image YesNoKonrad · May 21, 2016 at 04:52 AM 2
Share

This is actually the simplest way to go i feel. I also like that it is a visually strong separation.

You can prevent the cursor from being able to select the line by using LabelField ins$$anonymous$$d of TextArea :)

avatar image
10

Answer by numberkruncher · Apr 13, 2012 at 03:09 AM

Here is the solution that I use in my editor scripts:

 static class CustomGUI {
 
     public static readonly GUIStyle splitter;
 
     static CustomGUI() {
         GUISkin skin = GUI.skin;
 
         splitter = new GUIStyle();
         splitter.normal.background = EditorGUIUtility.whiteTexture;
         splitter.stretchWidth = true;
         splitter.margin = new RectOffset(0, 0, 7, 7);
     }
 
     private static readonly Color splitterColor = EditorGUIUtility.isProSkin ? new Color(0.157f, 0.157f, 0.157f) : new Color(0.5f, 0.5f, 0.5f);
     
     // GUILayout Style
     public static void Splitter(Color rgb, float thickness = 1) {
         Rect position = GUILayoutUtility.GetRect(GUIContent.none, splitter, GUILayout.Height(thickness));
 
         if (Event.current.type == EventType.Repaint) {
             Color restoreColor = GUI.color;
             GUI.color = rgb;
             splitter.Draw(position, false, false, false, false);
             GUI.color = restoreColor;
         }
     }
 
     public static void Splitter(float thickness, GUIStyle splitterStyle) {
         Rect position = GUILayoutUtility.GetRect(GUIContent.none, splitterStyle, GUILayout.Height(thickness));
 
         if (Event.current.type == EventType.Repaint) {
             Color restoreColor = GUI.color;
             GUI.color = splitterColor;
             splitterStyle.Draw(position, false, false, false, false);
             GUI.color = restoreColor;
         }
     }
 
     public static void Splitter(float thickness = 1) {
         Splitter(thickness, splitter);
     }
 
     // GUI Style
     public static void Splitter(Rect position) {
         if (Event.current.type == EventType.Repaint) {
             Color restoreColor = GUI.color;
             GUI.color = splitterColor;
             splitter.Draw(position, false, false, false, false);
             GUI.color = restoreColor;
         }
     }
 
 }
Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Steven-1 · Jan 09, 2013 at 03:37 PM 0
Share

Doesn't work for editor stuff (EditorGUILayout.Box() doesn't exist), which is what he asked, and what I'm looking for :s

avatar image numberkruncher · Jan 09, 2013 at 03:52 PM 1
Share

@Steven-1 You can use GUILayout.Box for editor GUI's or alternatively GUI.skin.box.Draw :-)

avatar image Steven-1 · Jan 09, 2013 at 04:05 PM 0
Share

oh, really? didn't know :s thanks

avatar image Steven-1 · Jan 09, 2013 at 04:40 PM 11
Share

how about just:

     GUILayout.Box("", new GUILayoutOption[]{GUILayout.ExpandWidth(true), GUILayout.Height(1)});

that works best for me

avatar image numberkruncher · Jan 09, 2013 at 04:45 PM 7
Share

@Steven-1 You can simplify this to GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));. The most efficient approach is to use the GUI.skin.box.Draw method purely for render events however.

Show more comments
avatar image
5

Answer by scadapop · Nov 26, 2014 at 03:48 PM

Ok so it might be a bit ugly but :

 public void displaySeparator()
 {
     GUILayout.Label("_________________________________________________________________________________________________________________________________________________________________________");
 }

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Riney · Mar 19, 2016 at 11:05 PM 0
Share

Ultimately this is what I picked, but added a \n to the end of the text. Works like a charm.

avatar image Albazcythe · Mar 18, 2017 at 02:56 PM 0
Share

Used this but added this to center the line a bit:

 GUIStyle st = new GUIStyle(GUI.skin.label);
 Vector2 coff = st.contentOffset;
 coff.y -= 5;
 st.contentOffset = coff;
 GUILayout.Label("_________________________________________", st);


avatar image
3

Answer by skalev · Oct 19, 2013 at 06:28 AM

I just found the full solution to this.

Using @Steven 1 method, but creating a custom gui skin, that setts all paddings to 1.

So first create a class that holds the custom style

 //Class to hold custom gui styles
 public static class MyGUIStyles
 {
     private static GUIStyle m_line = null;
 
     //constructor
     static LOGDGUIStyles()
     {
 
         m_line = new GUIStyle("box");
         m_line.border.top = m_line.border.bottom = 1;
         m_line.margin.top = m_line.margin.bottom = 1;
         m_line.padding.top = m_line.padding.bottom = 1;
     }
     
     public static GUIStyle EditorLine
     {
         get { return m_line; }
     }
 }


Then just call:

 GUILayout.Box(GUIContent.none, GUIStyles.EditorLine , GUILayout.ExpandWidth(true), GUILayout.Height(1f));

make sure you use EditorGUIUtility.LookLikeInspector(); before hand

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image YinXiaozhou · Sep 19, 2016 at 02:55 AM 0
Share

I took this. But you may want to set the left&right to 0, since there's 1 pixel space on both side of the line.

  • 1
  • 2
  • 3
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

25 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Any way to attach a bit of code to individual UI Windows [Editor] 1 Answer

Custom Prfab Editor Window 0 Answers

What is the best way to draw icons in Unity's Hierarchy window? 1 Answer

How do I code my own custom built blend tree node as seen in the Animation Controller Editor Window? 1 Answer

Editor Window Views 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges