- Home /
Enums as a dropdown in inspector in C#
How can I make enum variables show as a dropdown in C#?
With this code they just show as int.
using UnityEngine; using System;
[Serializable] public class SimpleExample { public enum Example { example1, example2 }
public Example DropdownHere;
}
Oh! Forgot to mention I'm actually using a list of SimpleExample class in a MonoBehaviour script. Just noticed that the enum works just fine when directly in the MonoBehaviour script, still I'd like to make it work this way.
Monobehaviour class script:
using UnityEngine; using System.Collections.Generic;
public class SimpleMonoBehaviourExample: MonoBehaviour { public List<SimpleExample> SimpleExampleList; }
Do you really need to ask this twice in five $$anonymous$$utes?
No, that was a bad mistake, sorry.
Deleted the other and fixed the flags for this one as this answer fits better my needs.
Answer by Lex · Jun 25, 2010 at 05:55 PM
Changing the List to an array of SimpleExamples works great.
using UnityEngine;
public class SimpleMonoBehaviourExample: MonoBehaviour { public SimpleExample[] SimpleExampleList; }
Thanks a lot I was looking for this answer... Hmm that is pretty much intriguing... anyone have an idea of why an array works, but not a list? It would be very interesting to know that :P...
A list is a class List<T>
and the Object[]
is a syntax
Answer by Ward Dewaele · Feb 22, 2011 at 12:05 AM
You just have to do
public Example DropdownHere = Example.example1;
to show up in the inspector (give it a value)
Your answer
Follow this Question
Related Questions
Type for layer selection 3 Answers
DropDownList with string array in Editor Inspector 5 Answers
Show a dropdown for C# classes in inspector. 2 Answers
Drop down with sizes 1 Answer
Dropdown like menus in the inspector 2 Answers