Last active
July 9, 2022 19:12
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEditor; | |
/// <summary> | |
/// Attribute to select a single layer. | |
/// </summary> | |
public class LayerAttribute : PropertyAttribute | |
{ | |
// NOTHING - just oxygen. | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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