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)