Unity Editor Scripting- Creating Horizontal Line

Saharukh Mollah
Nov 15, 2021

--

Creating Horizontal Line for your editor script can be a bit difficult for new learners. There are multiple approaches to create a horizontal line but I follow few of the below methods .

  1. Using the EditorGUILayout.LabelField

You can use LabelField and create a slider without any value to make it look like a line.

Code:

EditorGUILayout.LabelField(“”, GUI.skin.horizontalSlider);

How it looks

2. Using Custom Draw Function.

Code:

public static void DrawUILine(Color color, int thickness = 2, int padding = 10)

{

Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(padding + thickness));

r.height = thickness;

r.y += padding / 2;

r.x -= 2;

r.width += 6;

EditorGUI.DrawRect(r, color);

}

This is the line using custom function
DrawUILine(Color , Thickness , Padding);

3. Using GUILayout.Box

Code:

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

Using GUILayout.Box

These are the few methods I use to draw a horizontal line in my tools.

--

--