Files
AppleHillsProduction/Assets/Editor/LayerPropertyDrawer.cs
tschesky 63cb3f1a8c Revamp the settings system (#7)
- A Settings Provider system to utilize addressables for loading settings at runtime
- An editor UI for easy modifications of the settings objects
- A split out developer settings functionality to keep gameplay and nitty-gritty details separately
- Most settings migrated out of game objects and into the new system
- An additional Editor utility for fetching the settings at editor runtime, for gizmos, visualization etc

Co-authored-by: Michal Pikulski <michal.a.pikulski@gmail.com>
Co-authored-by: AlexanderT <alexander@foolhardyhorizons.com>
Reviewed-on: #7
2025-09-24 13:33:43 +00:00

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();
}
}
}