Thursday, January 15, 2026
spot_img

How can I take advantage of EditorGUI.indentLevel++; to assemble the fitting construction in my inspector editor script?


utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEditor;
utilizing UnityEditorInternal;
utilizing UnityEngine;

[CustomEditor(typeof(DialogueTrigger))]
public class DialogueTriggerEditor : Editor
{
    personal SerializedProperty _conversations;

    personal void OnEnable()
    {
        _conversations = serializedObject.FindProperty("conversations");
    }

    public override void OnInspectorGUI()
    {
        //base.OnInspectorGUI();

        serializedObject.Replace();

        _conversations.arraySize = EditorGUILayout.IntField("Conversations Measurement", _conversations.arraySize);

        for (int x = 0; x < _conversations.arraySize; x++)
        {
            var dialog = _conversations.GetArrayElementAtIndex(x);

            var conversationName = dialog.FindPropertyRelative("conversationName");

            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(conversationName);

            EditorGUI.indentLevel++;
            var _dialogues = dialog.FindPropertyRelative("Dialogues");

            _dialogues.arraySize = EditorGUILayout.IntField("Dialogues measurement", _dialogues.arraySize);

            for (int i = 0; i < _dialogues.arraySize; i++)
            {
                var dialogue = _dialogues.GetArrayElementAtIndex(i);
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(dialogue, new GUIContent("Dialogue " + i), true);

                EditorGUI.indentLevel--;
            }

            if (_dialogues.arraySize > 0)
            {
                if (GUILayout.Button("Save Dialog"))
                {

                }
            }

            EditorGUI.indentLevel--;
        }

        serializedObject.ApplyModifiedProperties();
    }
}

I am utilizing in some locations the EditorGUI.indentLevel++; however the result’s this:

How can I take advantage of EditorGUI.indentLevel++; to assemble the fitting construction in my inspector editor script?

However I need it to be like this:

Conversations Measurement
     Dialog Identify
          Dialogue measurement
     Dialog Identify
          Dialogue measurement
     Dialog Identify
          Dialogue measurement
     Dialog Identify
          Dialogue measurement

That is the way it ought to seem like within the Inspector.

The issue is on this half:

EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(conversationName);
EditorGUI.indentLevel++;
var _dialogues = dialog.FindPropertyRelative("Dialogues");
_dialogues.arraySize = EditorGUILayout.IntField("Dialogues measurement", _dialogues.arraySize);

I am unable to make the “Dialog” Identify the “Dialogues” and the “Dialogues measurement” the identical as I needed.

The “Dialogues” is okay however the others usually are not.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -spot_img

Latest Articles