Could anyone tell me the correct way to use an enum mask field in c#. Here’s the relevent bits of code I’m using:
FootprintManager.cs
public class FootprintManager : MonoBehaviour {
public enum foundTag {none = 0, any = 1, interior = 2, cornerExt = 3, cornerInt = 4};
}
FootprintEditor.cs
[CustomEditor(typeof(Footprint))]
public class FootprintEditor : Editor {
public override void OnInspectorGUI(){
FootprintManager.foundTag = EditorGUILayout.EnumMaskField("Masks", FootprintManager.foundTag);
}
}
This is how I use EnumMaskField to create a custom mask property in inspector, using C#.
public class TileNode: MonoBehaviour
{
public TileType tileTypeMask = 0;
public enum TileType
{
Normal = 1,
Air = 2,
Water = 4,
Wall = 8,
//etc = 16,
//etc = 32,
}
}
[CustomEditor(typeof(TileNode))]
public class TileNodeEditor : Editor
{
public SerializedProperty tileTypeMask;
void OnEnable()
{
tileTypeMask = serializedObject.FindProperty("tileTypeMask");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
tileTypeMask.intValue = (int)((TileNode.TileType)EditorGUILayout.EnumMaskField("Tile Type Mask", (TileNode.TileType)tileTypeMask.intValue));
serializedObject.ApplyModifiedProperties();
}
}
The EnumMaskField is used to edit a bit-mask. Your enum values doesn’t seem to reflect a bit mask. I guess you want something like that:
public enum foundTag
{
none = 0,
any = 0xFFFF, // bits: 11111111 11111111
interior = 1, // bits: 00000000 00000001
cornerExt = 2, // bits: 00000000 00000010
cornerInt = 4 // bits: 00000000 00000100
};
I hope you are familiar with bitmasks? If not i can add some basics 