12.4 C
New York
Saturday, May 24, 2025

How can I take advantage of editorgui.indentlevel ++? To construct the proper construction within the script of my inspector editor?


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 Dimension", _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 dimension", _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’m utilizing the editorgui.indentlevel ++ in some locations; However the result’s this:

However I need it to be like this:

Conversations Dimension
     Dialog Identify
          Dialogue dimension
     Dialog Identify
          Dialogue dimension
     Dialog Identify
          Dialogue dimension
     Dialog Identify
          Dialogue dimension

That is the way it needs to be seen 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 dimension", _dialogues.arraySize);

I can not make the “dialog” title “dialogues” and the “dialogue dimension” the identical as I needed.

The “dialogues” are wonderful, however the others don’t.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles