55 lines
2.0 KiB
C#
55 lines
2.0 KiB
C#
using UnityEngine;
|
|
using UnityEditor;
|
|
|
|
namespace AppleHills.Core.Settings.Editor
|
|
{
|
|
/// <summary>
|
|
/// Custom property drawer for layer fields to display a dropdown with layer names
|
|
/// </summary>
|
|
[CustomPropertyDrawer(typeof(LayerAttribute))]
|
|
public class LayerPropertyDrawer : PropertyDrawer
|
|
{
|
|
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
|
{
|
|
EditorGUI.BeginProperty(position, label, property);
|
|
|
|
// Draw a nice layer selection dropdown like the one in Unity inspector
|
|
if (property.propertyType == SerializedPropertyType.Integer)
|
|
{
|
|
property.intValue = EditorGUI.LayerField(position, label, property.intValue);
|
|
}
|
|
else
|
|
{
|
|
EditorGUI.LabelField(position, label.text, "Use [Layer] with int fields only");
|
|
}
|
|
|
|
EditorGUI.EndProperty();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Custom property drawer for LayerMask fields to display a mask dropdown with layer names
|
|
/// </summary>
|
|
[CustomPropertyDrawer(typeof(LayerMaskAttribute))]
|
|
public class LayerMaskPropertyDrawer : PropertyDrawer
|
|
{
|
|
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
|
{
|
|
EditorGUI.BeginProperty(position, label, property);
|
|
|
|
// Draw a nice layer mask selection like the one in Unity inspector
|
|
if (property.propertyType == SerializedPropertyType.LayerMask)
|
|
{
|
|
property.intValue = EditorGUI.MaskField(position, label,
|
|
property.intValue, UnityEditorInternal.InternalEditorUtility.layers);
|
|
}
|
|
else
|
|
{
|
|
EditorGUI.LabelField(position, label.text, "Use [LayerMask] with LayerMask fields only");
|
|
}
|
|
|
|
EditorGUI.EndProperty();
|
|
}
|
|
}
|
|
}
|