blob: 06f95603a42df20834911b57ccb8d89b9aa759a4 (
plain)
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
|
using UnityEditor;
using UnityEngine;
namespace Pathfinding {
[CustomPropertyDrawer(typeof(GraphMask))]
public class GraphMaskDrawer : PropertyDrawer {
string[] graphLabels = new string[32];
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) {
// Make sure the AstarPath object is initialized and the graphs are loaded, this is required to be able to show graph names in the mask popup
AstarPath.FindAstarPath();
for (int i = 0; i < graphLabels.Length; i++) {
if (AstarPath.active == null || AstarPath.active.data.graphs == null || i >= AstarPath.active.data.graphs.Length || AstarPath.active.data.graphs[i] == null) graphLabels[i] = "Graph " + i + (i == 31 ? "+" : "");
else {
graphLabels[i] = AstarPath.active.data.graphs[i].name + " (graph " + i + ")";
}
}
EditorGUI.BeginChangeCheck();
EditorGUI.showMixedValue = property.hasMultipleDifferentValues;
var valueProp = property.FindPropertyRelative("value");
int newVal = EditorGUI.MaskField(position, label, valueProp.intValue, graphLabels);
if (EditorGUI.EndChangeCheck()) {
valueProp.intValue = newVal;
}
EditorGUI.showMixedValue = false;
}
}
}
|