public class LayerMaskAttribute : PropertyAttribute {
public Type type;
public LayerMaskAttribute(Type type)
{
this.type = type;
}
}
[CustomPropertyDrawer(typeof(LayerMaskAttribute))]
public class LayerMaskAttributeDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
LayerMaskAttribute range = attribute as LayerMaskAttribute;
property.intValue = EditorGUI.MaskField(position,label, property.intValue, range.type.GetEnumNames());
}
}
[Unity] 利用 PropertyAttribute和PropertyDrawer修改由标签标记的属性在Editor内的显示目标 将int在编辑器内修改成layermask的显示样式,如下图所示:public class LayerMaskAttribute : PropertyAttribute { public Type type; public LayerMaskAttribute(Type type) { this.type = type; }