Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by dekarguy · Sep 28, 2010 at 06:15 PM · editorvariablebooleanenumflag

Flag structure variable in unity editor

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:

enum { FLAG1 = 1 << 0, FLAG2 = 1 << 1, FLAG2 = 1 << 2, FLAG3 = 1 << 3 };
u8 myFlags = FLAG1 | FLAG3;
myFlags |= FLAG2;

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by skovacs1 · Sep 28, 2010 at 06:57 PM

An enum works just like that.

enum foo {bar, bash, bang};
var blah : foo;

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dekarguy · Sep 28, 2010 at 07:04 PM 0
Share

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.

avatar image skovacs1 · Sep 28, 2010 at 10:09 PM 0
Share

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 Layer$$anonymous$$ask 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.

avatar image dekarguy · Sep 30, 2010 at 05:01 PM 0
Share

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.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

ANOTHER Boolean Problem 1 Answer

DrawGizmo attribute: GizmoType arg with incompatible flag values 0 Answers

get enum value using an object name... 0 Answers

Access a variable from another script in update function 1 Answer

Use enum value as a index variable of a list 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges