-
Notifications
You must be signed in to change notification settings - Fork 0
MaskLayer
Ondřej Kačírek edited this page May 3, 2025
·
1 revision
MaskLayer
is a serializable struct that simplifies selecting a single Unity layer in the Inspector.
Unity's LayerMask
supports multiple selections, but sometimes only one layer should be selectable. MaskLayer
enforces a single layer and integrates with the Unity Editor for clean selection.
- Single layer selection
- Unity Editor integration with custom property drawer
- Implicitly returns layer index and bitmask
[SerializeField] private MaskLayer maskLayer;
int layerIndex = maskLayer.layerIndex;
int layerMask = maskLayer.LayerMask;
-
private int _layerIndex
— stores the selected layer index.
-
int layerIndex
— returns the selected layer index. -
int LayerMask
— returns1 << layerIndex
.
-
void SetLayer(int layer)
— sets the layer if the index is between 1 and 31. -
MaskLayer(int layer)
— constructor with validation.
A CustomPropertyDrawer
is provided for Unity Editor that renders a dropdown layer field in the inspector.