|
How can I create a variable that looks like an enum in the inspector? Do I have to declare it as a class? IE Or is there a more straightforward way of doing it?
(comments are locked)
|
|
What an enum is, is a set of non-editable named values. You can then make variables of that enum type, and those variables will be settable to any of the named values (with a useful dropdown box). It sounds like you don't actually mean "enum". Do you just want to organize a set of variables into its own scope? If so, the code you're using above is the most straightforward way of doing it. You shouldn't call it "enum", though, as that's an unrelated concept. Actually I didn't. :) "a variable that looks like an enum in the inspector?" I thought scope mean public, private or static. (I'm self taught) Not entirely familiar with the correct terminology. Just wanted to make sure I was doing it right, which I take it I am. Thanks. :)
May 20 '11 at 11:24 PM
NewfieJoe
I also wanted to set some of them with labels instead of numbers so they could be selected from a dropdown list. Right now I just use an enum for the list of labels. Then a separate editable group of variables with "Label" entries and IDs that match the enum dropdown which seems clunky.
May 20 '11 at 11:32 PM
NewfieJoe
"Scope" is one of those things that programmers use to mean way too many different things. :-) The more unambiguous term for private/public/static is "protection level", but I've definitely seen people call it "scope".
May 23 '11 at 01:38 PM
sneftel
If you want to use an enum-style dropdown box to select a set of values, you have a couple of options. The first is, as you say, use an enum for the dropdown, then translate from that to what you actually want. The other way is to move to CustomEditor. These can be time-consuming to write and keep up to date, but they're the only way to have full control over the inspector.
May 23 '11 at 01:38 PM
sneftel
Custom editors (or often more practical/easier: custom inspectors) are definitely worth the effort if you're working on a complicated script.
May 23 '11 at 01:44 PM
Joshua
(comments are locked)
|
|
No that just declares enumerator constants that can't be edited. I need something that is visible in the editor and can be edited during runtime. So it looks like an enumerator but is read/write instead of read only. Just for legibility for other team members who don't read code very well.
May 20 '11 at 10:05 PM
NewfieJoe
So I can use something like if( player.health > player.maxhealth ). It also lets me organize my variables into sub-groups. My main routine has over 100 variables, if they were one long list it would be incomprehensible. Together this makes variables human readable and organized and makes my code read like pseudocode.
May 20 '11 at 10:05 PM
NewfieJoe
(comments are locked)
|

for anyone wanting this functionality the above code works btw. I just wondered if there was a syntax for a more intuitive way of declaring it similar to: public enum var myvar { var1:int, var2:int } or if I was already doing it correctly and to leave it as-is