Files
SampleRenderPasses/Assets/Attributes/Editor/NavMeshMaskDrawer.cs
2025-05-18 22:39:39 +03:00

36 lines
1.2 KiB
C#

#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
namespace Golems.Attributes
{
[CustomPropertyDrawer(typeof(NavMeshMaskAttribute))]
public class NavMeshMaskDrawer : PropertyDrawer
{
// Draw the property inside the given rect
public override void OnGUI(Rect position, SerializedProperty serializedProperty, GUIContent label)
{
EditorGUI.BeginChangeCheck();
string[] navMeshAreaNames = GameObjectUtility.GetNavMeshAreaNames();
int navMeshArea = serializedProperty.intValue;
int selectedIndex = -1;
for (int i = 0; i < navMeshAreaNames.Length; i++)
{
if (GameObjectUtility.GetNavMeshAreaFromName(navMeshAreaNames[i]) == navMeshArea)
{
selectedIndex = i;
break;
}
}
int num = EditorGUI.Popup(position, "Navigation Area", selectedIndex, navMeshAreaNames);
if (EditorGUI.EndChangeCheck())
{
int navMeshAreaFromName = GameObjectUtility.GetNavMeshAreaFromName(navMeshAreaNames[num]);
serializedProperty.intValue = navMeshAreaFromName;
}
}
}
}