Skip to content

Commit 3066987

Browse files
committed
Update README with caveats for Unity 2019
1 parent c7b9570 commit 3066987

File tree

1 file changed

+59
-15
lines changed

1 file changed

+59
-15
lines changed

README.md

+59-15
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,74 @@ https://github.com/gilzoide/EnumBitSet.git
2424

2525

2626
## 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:
2929

3030
```cs
3131
using System;
3232
using UnityEngine;
33-
using EnumBitSet;
33+
using Gilzoide.EnumBitSet;
3434

35-
public class ScriptWithBitSet : MonoBehaviour
35+
public enum TestEnum
36+
{
37+
Zero, One, Two, Three
38+
}
39+
40+
[Flags]
41+
public enum TestEnumFlags
3642
{
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+
{
4848
public EnumBitSet32<TestEnum> aBitset;
4949
public EnumBitSet64<TestEnumFlags> anotherBitset;
5050
}
5151
```
5252

5353
![](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

Comments
 (0)