Unity C # make check boxes with enum (enum)

Source: Internet
Author: User

Recently in the project to do test script with some Boolean methods to do the switch, suddenly thought can make a check box control switch.

The first collection of online information, basically the same, there is no more explanation, the code is attached:

1  Public class enumflagsattribute:propertyattribute{}
1[Custompropertydrawer (typeof(Enumflagsattribute))]2PublicclassEnumflagsdrawer:propetydrawer3 {4PublicOverride voidOngui (Rect position,serializedproperty property,guicontent label)5     {6         /*The Draw enumeration check box, 0-nothing,-1-everything, the other is the sum of the enumerations7 enumeration value (2 x Power): 2 of 0 Power =1,2 1 Power =2,2 2 power =4,8,16 ...8         */9Property.intvalue =Editorgui.maskfield (position,label,property.intvalue,property.enumnames);Ten     } One}

Here are the applications:

1 [System.flags]2  Public enumTestenum3 {4One=1,5two=2,6Three=4,7Four=8,8 }9 Ten  Public classTestenum One { A [Enumflags] -      Publictestenum _testenum; -      the     if((int) (_testenum&testenum.one) ==1) - DoSomething1 (); -     if((int) (_testenum&testenum.two) ==2) - DoSomething2 (); +     if((int) (_testenum&testenum.three) ==4) - DoSomething3 (); +     if((int) (_testenum&testenum.four) ==8) ADoSomething4 ();

Unity C # make check boxes with enum (enum)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.