|
Is there a construct in JavaScript or Unity which behaves like a typical flag structure and have an associated editor. For example, in C++ I would have:
And I would imagine an editor would work like a list of booleans, or an enum dropdown with checks for which values are present. Thanks for the help
(comments are locked)
|
|
An enum works just like that.
In the inspector, the variable blah has a drop-down of values from the enum foo. To allow for multiple simultaneous selections is a bit trickier. That requires something that will generate an IntPopUp. One of the things that gets in the way is that .Net doesn't implicitly treat ints as enum types (and vice versa) and another is that Unity's inspector doesn't seem to do anything special with the System.FlagsAttribute as near as I can tell. I'm still digging to find a way to serialize something in generic other than a LayerMask which generates an IntPopUp. As it stands, the only way that I can see is to create a CustomEditor for scripts and a custom class of integer or enum for which your CustomEditor will generate an IntPopUp. Please see these scripts for an idea of how to get started on that. The case I am looking for is where in the inspector I can select both bar and bash and if I query foo I can test if bar or bash are selected.
Sep 28 '10 at 07:04 PM
dekarguy
Ah! A type which allows for multiple simultaneous selections in the editor from a list of preset values which acts as a bitmask. I didn't get that from the question - Sorry. The only type I know of that behaves in this way is the LayerMask struct and I get the feeling that there's some editor scripted magic going on to enable that (with the mixed, nothing and everything options). I'll add what information I've found on this to the answer.
Sep 28 '10 at 10:09 PM
skovacs1
Thanks for the info. I resorted to creating a new class containing a bunch of bools, which I then added as var's for my behaviors. Achieves representing flags, just not quite the interface I was looking for. I'll have to look into the IntPopUp stuff and CustomEditors a bit more.
Sep 30 '10 at 05:01 PM
dekarguy
(comments are locked)
|
