-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathLayerDrawer.cs
34 lines (30 loc) · 1.04 KB
/
LayerDrawer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using cmdwtf.UnityTools.Attributes;
using UnityEditor;
using UnityEngine;
namespace cmdwtf.UnityTools.Editor
{
// via https://answers.unity.com/questions/609385/type-for-layer-selection.html
[UnityEditor.CustomPropertyDrawer(typeof(LayerAttribute))]
public class LayerDrawer : CustomPropertyDrawer
{
private const int MinLayerValue = 0;
private const int MaxLayerValue = 31;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
int index = property.intValue;
if (index > MaxLayerValue)
{
Debug.LogWarning($"{nameof(LayerDrawer)}: layer index is to high: '{index}', is set to {MaxLayerValue}");
index = MaxLayerValue;
}
else if (index < MinLayerValue)
{
Debug.LogWarning($"{nameof(LayerDrawer)}: layer index is to low: '{index}', is set to {MinLayerValue}");
index = MinLayerValue;
}
property.intValue = EditorGUI.LayerField(position, label, index);
EditorGUI.EndProperty();
}
}
}