Skip to content

Instantly share code, notes, and snippets.

@paulhayes
Last active July 9, 2022 19:12
Show Gist options
  • Save paulhayes/9e65a4c4d529311541597e08c4fcb765 to your computer and use it in GitHub Desktop.
Save paulhayes/9e65a4c4d529311541597e08c4fcb765 to your computer and use it in GitHub Desktop.
Unity Single layer dropdown from this forum post https://answers.unity.com/questions/609385/type-for-layer-selection.html
using UnityEditor;
/// <summary>
/// Attribute to select a single layer.
/// </summary>
public class LayerAttribute : PropertyAttribute
{
// NOTHING - just oxygen.
}
using UnityEditor;
using UnityEngine;
[CustomPropertyDrawer(typeof(LayerAttribute))]
public class LayerAttributeEditor : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
property.intValue = EditorGUI.LayerField(position, label, property.intValue);
EditorGUI.EndProperty();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment