Class LayerFieldAttribute
Marks an int field so the Inspector renders it as a layer selection dropdown
instead of a raw integer input.
Inherited Members
Namespace: Scylla.Core.Attributes
Assembly: ScyllaCore.dll
Syntax
[AttributeUsage(AttributeTargets.Field)]
public sealed class LayerFieldAttribute : PropertyAttribute
Remarks
When this attribute is applied to a serialized int field, Unity's custom
property drawer (LayerFieldDrawer) replaces the default integer field with a
popup that lists every layer currently defined in the project's Physics settings
(i.e. the same layers shown in Unity's built-in EditorGUI.LayerField).
The selected layer's index is stored in the backing field.
Using this attribute instead of a plain int field provides two concrete
benefits:
- It prevents hardcoded layer indices that silently break when layers are reordered or renamed in the Project Settings.
- It makes the Inspector self-documenting: designers and engineers can see layer names rather than opaque integers.
Field type requirement: The decorated field must be of type int. If
the attribute is placed on any other type, the Inspector will display a red error
help box instead of the dropdown, and the field will not be editable until the
type is corrected.
The stored integer value is the layer index (0-31), compatible with
Physics.Raycast, LayerMask, and other Unity APIs that accept a
layer index directly. To convert the stored index to a bitmask suitable for
LayerMask parameters, use the left-shift operator: 1 << _myLayer.
public class RaycastController : MonoBehaviour
{
/* Dropdown showing all project layers; stores the layer index as int. */
[LayerField]
[SerializeField] private int _groundLayer;
[LayerField]
[SerializeField] private int _enemyLayer;
public bool IsGrounded()
{
/* Convert index to LayerMask bitmask with left-shift. */
return Physics.Raycast(transform.position, Vector3.down, 1f, 1 << _groundLayer);
}
}