- Home /
EnumPopup in Javascript?
How do I do this (without also adding #pragma downcast
):
#pragma strict
enum Op { Foo, Bar }
op = EditorGUILayout.EnumPopup("Operator: ", op);
(gives error BCE0022: Cannot convert 'System.Enum' to 'Op'
)
In C#, I could:
op = (Op)EditorGUILayout.EnumPopup("Operator: ", op);
But what is the equivalent for JS?
If pragma strict is now enforced on iOS (I wish it was on all platforms), it seems that much of the documentation examples would not work (my code above is as-per the EnumPopup
docs). I find it a bit annoying that the documentation often shows how to do stuff, but with code that only works without #pragma strict (for loops and non-generic GetComponent() being the worst).
Non-generic GetComponent works fine with #pragma strict in Unity 3.4, since it returns the type you are getting rather than Component. You can add "#pragma implicit" if you want to do stuff like "`for (i = 0...`".
I want casting of enums - that EnumPopup requires in order to be used - surely a Unity function doesn't require a set of pragmas in order to be used.
I don't want any "magic" happening, which is why I do not want downcast
, nor implicit
. The more picky a compiler is the better.
By "non-generic", I mean GetComponent(T)
, not GetComponent.<T>()
.
Answer by Waz · Aug 06, 2011 at 12:26 AM
Best I've come up with is:
op = System.Convert.ToInt32(EditorGUILayout.EnumPopup(op));
Which is too ugly to accept this as the answer.
I'll take ugly any day as long as it works (well for program$$anonymous$$g at least)
Answer by _Daniel_ · Jun 09, 2013 at 10:39 PM
I believe casting is done with the "as" operator in javascript. So it would go like this:
op = EditorGUILayout.EnumPopup("Operator: ", op) as OP;
Your answer
Follow this Question
Related Questions
Object to int 1 Answer
Display TM symbol in enum on GUI 1 Answer
Show enum in a loop in on GUI 1 Answer
Classes and type casting? 2 Answers
How to use EnumPopup 1 Answer