First Commit
This commit is contained in:
35
Assets/Attributes/Editor/NavMeshMaskDrawer.cs
Normal file
35
Assets/Attributes/Editor/NavMeshMaskDrawer.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
#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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user