Unity Editor Scripting- Creating Horizontal Line
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 .
- 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);
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);
}
3. Using GUILayout.Box
Code:
GUILayout.Box(“”, new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(1) });
These are the few methods I use to draw a horizontal line in my tools.