how to create a drop-down menu in inspector

Hi, I want to bring the presentation in the dialog class to a drop-down list.
But I hit the chairs.

help


What you need is a PropertyDrawer (to draw a serialized field declared in a MonoBehaviour), not a CustomEditor.

Following code not tested because you have provided your code as images instead of plain text…

[CustomPropertyDrawer(typeof( Dialog ))]
public class DialogDrawer : PropertyDrawer
{
    int _choiceIndex;
    string[] _choices = new string[]{ "User1", "User2" };

	public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        SerializedProperty userIndexProperty = property.FindPropertyRelative("UserIndex");

        EditorGUI.BeginChangeCheck();
        _choiceIndex = EditorGUI.Popup( position, userIndexProperty.intValue, _choices );
        if( EditorGUI.EndChangeCheck() )
        {
            userIndexProperty.intValue = _choiceIndex;
        }
	}
}

I think you’re looking for something like this?

public class DropDownEditor : Editor
{
    private Dialog diag;
    private int selectedIndex = 0;

    private void OnEnable()
    {
        diag = (Dialog)target;
    }

    public override void OnInspectorGUI()
    {
        selectedIndex = EditorGUILayout.Popup("Label", selectedIndex, diag.nameusers);
    }
}

Edit: Note that custom editors can only be written for scripts which inherit from MonoBehaviour.