EditorGUILayout.LabelField

EditorGUILayout.LabelField is a method provided by the UnityEditor namespace in Unity that allows you to display a label in the Unity editor’s inspector window. It is commonly used to provide information or headings within a custom editor script.

The LabelField method has several overloaded versions, but the most basic one takes a string as a parameter, representing the text to be displayed in the label. Here’s an example of using EditorGUILayout.LabelField to display a simple label:

EditorGUILayout.LabelField("Hello, Unity!");

This code will display a label with the text “Hello, Unity!” in the inspector.

LabelField can also take additional parameters to customize the appearance of the label. Here are some examples of using different parameters with LabelField:

1. **Label with a Tooltip**:

EditorGUILayout.LabelField(new GUIContent("Label with Tooltip", "This is a tooltip message."));

This code displays a label with the specified text and adds a tooltip that appears when you hover over the label.

2. **Label with a Style**:

GUIStyle boldLabelStyle = new GUIStyle(EditorStyles.boldLabel);
EditorGUILayout.LabelField("Bold Label", boldLabelStyle);

In this example, a custom GUIStyle object named boldLabelStyle is created by assigning it the EditorStyles.boldLabel style. The label will be displayed with the bold style applied.

3. **Label with Rich Text**:

EditorGUILayout.LabelField("<color=red>Red Label</color>", EditorStyles.label);

This code demonstrates the use of rich text in a label. The label text is wrapped in HTML-style tags to specify the color. The EditorStyles.label style is used to apply the default label style.

EditorGUILayout.LabelField

These are just a few examples of how you can use EditorGUILayout.LabelField to display labels with different customizations. You can combine LabelField with other GUI elements and styles provided by the EditorGUILayout and EditorStyles classes to create informative and visually appealing custom editor scripts in Unity.

Related Articles

Responses

Your email address will not be published. Required fields are marked *