-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNavMeshAreaMaskAttribute.cs
More file actions
42 lines (35 loc) · 1.31 KB
/
NavMeshAreaMaskAttribute.cs
File metadata and controls
42 lines (35 loc) · 1.31 KB
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
35
36
37
38
39
40
41
using System;
using System.Diagnostics;
using UnityEditor;
using UnityEngine;
using Debug = UnityEngine.Debug;
namespace Jackey.Utilities.Attributes {
/// <summary>
/// Displays a Mask field of all NavMesh areas in the inspector
/// </summary>
[AttributeUsage(AttributeTargets.Field)]
[Conditional("UNITY_EDITOR")]
public sealed class NavMeshAreaMaskAttribute : PropertyAttribute { }
#if UNITY_EDITOR
namespace PropertyDrawers {
[CustomPropertyDrawer(typeof(NavMeshAreaMaskAttribute))]
public class NavMeshAreaPropertyDrawer : PropertyDrawer {
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
return EditorGUI.GetPropertyHeight(property, label);
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
if (property.propertyType != SerializedPropertyType.Integer) {
Debug.LogWarning("The NavMeshAreaMask attribute only supports application on int fields");
return;
}
label = EditorGUI.BeginProperty(position, label, property);
EditorGUI.BeginChangeCheck();
int maskFieldValue = EditorGUI.MaskField(position, label, property.intValue, GameObjectUtility.GetNavMeshAreaNames());
if (EditorGUI.EndChangeCheck())
property.intValue = maskFieldValue;
EditorGUI.EndProperty();
}
}
}
#endif
}