Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Forked from ryan-at-melcher/LayerFieldAttribute.cs
Created November 26, 2025 10:01
Show Gist options
  • Select an option

  • Save unitycoder/37cdc522587ade2bc9a944974b43a859 to your computer and use it in GitHub Desktop.

Select an option

Save unitycoder/37cdc522587ade2bc9a944974b43a859 to your computer and use it in GitHub Desktop.

Revisions

  1. @ryan-at-melcher ryan-at-melcher created this gist Aug 21, 2024.
    10 changes: 10 additions & 0 deletions LayerFieldAttribute.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    using UnityEngine;

    /// <summary>
    /// Allows a single GameObject layer to be selected from the inspector when applied to an
    /// <see langword="int" /> field. Intended to be used when a <see cref="LayerMask" />'s
    /// multiselection is not suitable.
    /// </summary>
    public class LayerFieldAttribute : PropertyAttribute
    {
    }
    14 changes: 14 additions & 0 deletions LayerFieldAttributeDrawer.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    using UnityEngine;
    using UnityEditor;

    [CustomPropertyDrawer(typeof(LayerFieldAttribute))]
    public class LayerFieldAttributeDrawer : PropertyDrawer
    {
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
    using (new EditorGUI.PropertyScope(position, label, property))
    {
    property.intValue = EditorGUI.LayerField(position, label, property.intValue);
    }
    }
    }