15 C
New York
Saturday, May 24, 2025

How can I take advantage of EditorGUI.indentLevel++; to assemble the precise 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
{
    non-public SerializedProperty _conversations;

    non-public 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:

However I need it to be like this:

Conversations Measurement
     Dialog Title
          Dialogue measurement
     Dialog Title
          Dialogue measurement
     Dialog Title
          Dialogue measurement
     Dialog Title
          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” Title the “Dialogues” and the “Dialogues measurement” the identical as I needed.

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

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles