@@ -24,30 +24,74 @@ https://github.com/gilzoide/EnumBitSet.git
24
24
25
25
26
26
## Unity 2020+ Serialization and Property Drawer
27
- In Unity 2020+, enum bitsets are serializable and there's a custom property
28
- drawer for selecting the containing enums:
27
+ In Unity 2020+, ` EnumBitSet ` s are serializable directly as generic classes.
28
+ There's also a custom property drawer for selecting the containing enums:
29
29
30
30
``` cs
31
31
using System ;
32
32
using UnityEngine ;
33
- using EnumBitSet ;
33
+ using Gilzoide . EnumBitSet ;
34
34
35
- public class ScriptWithBitSet : MonoBehaviour
35
+ public enum TestEnum
36
+ {
37
+ Zero , One , Two , Three
38
+ }
39
+
40
+ [Flags ]
41
+ public enum TestEnumFlags
36
42
{
37
- public enum TestEnum
38
- {
39
- Zero , One , Two , Three
40
- }
41
-
42
- [Flags ]
43
- public enum TestEnumFlags
44
- {
45
- Zero = 1 << 0 , One = 1 << 1 , Two = 1 << 2 , Three = 1 << 3
46
- }
47
-
43
+ Zero = 1 << 0 , One = 1 << 1 , Two = 1 << 2 , Three = 1 << 3
44
+ }
45
+
46
+ public class ScriptWithBitSet : MonoBehaviour
47
+ {
48
48
public EnumBitSet32 <TestEnum > aBitset ;
49
49
public EnumBitSet64 <TestEnumFlags > anotherBitset ;
50
50
}
51
51
```
52
52
53
53
![ ] ( Extras~/CustomDrawer.png )
54
+
55
+ ## Unity 2019- Serialization and Property Drawer
56
+ In Unity 2019 and earlier, create non-generic classes that
57
+ inherit from the generic ones:
58
+
59
+ ``` cs
60
+ using System ;
61
+ using UnityEngine ;
62
+ using Gilzoide .EnumBitSet ;
63
+
64
+ public enum TestEnum
65
+ {
66
+ Zero , One , Two , Three
67
+ }
68
+
69
+ [Flags ]
70
+ public enum TestEnumFlags
71
+ {
72
+ Zero = 1 << 0 , One = 1 << 1 , Two = 1 << 2 , Three = 1 << 3
73
+ }
74
+
75
+ [Serializable ]
76
+ public class TestEnumBitSet32 : EnumBitSet32 <TestEnum > {}
77
+
78
+ [Serializable ]
79
+ public class TestEnumFlagsBitSet64 : EnumBitSet64 <TestEnumFlags > {}
80
+
81
+ public class ScriptWithBitSet : MonoBehaviour
82
+ {
83
+ public EnumBitSet32 <TestEnum > aBitset ;
84
+ public EnumBitSet64 <TestEnumFlags > anotherBitset ;
85
+ }
86
+ ```
87
+
88
+ For the custom Property Drawer, the same applies.
89
+ Create a class that inherits from ` EnumBitSetPropertyDrawer ` :
90
+
91
+ ``` cs
92
+ using UnityEditor ;
93
+ using Gilzoide .EnumBitSet .Editor ;
94
+
95
+ [CustomPropertyDrawer (typeof (TestEnumBitSet32 ))]
96
+ public class TestEnumBitSet32PropertyDrawer : EnumBitSetPropertyDrawer {}
97
+ ```
0 commit comments