Skip to content

Instantly share code, notes, and snippets.

@immrsv
Created May 20, 2018 04:31
Show Gist options
  • Save immrsv/6672cf6c404096dbe4809ff0e24e6df1 to your computer and use it in GitHub Desktop.
Save immrsv/6672cf6c404096dbe4809ff0e24e6df1 to your computer and use it in GitHub Desktop.
Display Unity Layers as drop-down in Inspector
using UnityEngine;
using System.Collections;
using UnityEditor;
// This defines how the TagList should be drawn
// in the inspector, when inspecting a GameObject with
// a MonoBehaviour which uses the TagList attribute
[CustomPropertyDrawer(typeof(UnityLayerAttribute))]
public class UnityLayerDrawer : PropertyDrawer
{
UnityLayerAttribute UnityLayer
{
get { return ((UnityLayerAttribute)attribute); }
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
if (property.isExpanded)
{
return 2 * EditorGUIUtility.singleLineHeight;
}
else
{
return EditorGUIUtility.singleLineHeight;
}
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
// Using BeginProperty / EndProperty on the parent property means that
// prefab override logic works on the entire property.
EditorGUI.BeginProperty(position, label, property);
//position = EditorGUI.PrefixLabel(position, label);
property.intValue = EditorGUI.LayerField(position, label, property.intValue);
//EditorGUI.PropertyField(position, property);
// Using BeginProperty / EndProperty on the parent property means that
// prefab override logic works on the entire property.
EditorGUI.EndProperty();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment