Cleanup the editor assembly and provide a tool overview doc
This commit is contained in:
54
Assets/Editor/CustomEditorsAndDrawers/LayerPropertyDrawer.cs
Normal file
54
Assets/Editor/CustomEditorsAndDrawers/LayerPropertyDrawer.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user