- Home /
Question by
digzelot · Apr 18, 2019 at 09:33 PM ·
listscustom-inspectorenumpopup
Enum-like menu to display list elements?
I really like how Enum's are displayed in the inspector: ie, you can click the field, see a drop down of all possible options, and select one.
I'm wondering if its possible to display a list in this fashion?
Comment
Best Answer
Answer by digzelot · Apr 19, 2019 at 03:20 AM
using UnityEditor;
using System.Collections.Generic;
[CustomEditor(typeof(StatList))]
public class StatListEditor: Editor
{
public List<string> statList = new List<string>()
{
"hp", "mp", "str", "lck", "dmg"
};
public int selectedIndex = 0;
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.PrefixLabel("Attributes");
selectedIndex = EditorGUILayout.Popup(selectedIndex, statList.ToArray());
serializedObject.ApplyModifiedProperties();
}
}
Your answer
Follow this Question
Related Questions
Enumerations in custom inspector C# 2 Answers
Custom Inspector List Resetting after Play 0 Answers
problems writing an enum range attribute 1 Answer
KeyCode in custom editor 2 Answers
List inside of a list in a custom window 0 Answers