summaryrefslogtreecommitdiff
path: root/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Editor/ProceduralGridMoverEditor.cs
blob: 4d125ef20527641c619ba1cd04c0d5b4073ccf6e (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;

namespace Pathfinding {
	[CustomEditor(typeof(ProceduralGraphMover))]
	[CanEditMultipleObjects]
	public class ProceduralGridMoverEditor : EditorBase {
		GUIContent[] graphLabels = new GUIContent[32];

		protected override void Inspector () {
			// 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] = new GUIContent("Graph " + i + (i == 31 ? "+" : ""));
				} else {
					graphLabels[i] = new GUIContent(AstarPath.active.data.graphs[i].name + " (graph " + i + ")");
				}
			}

			Popup("graphIndex", graphLabels, "Graph");
			PropertyField("target");

			// Only show the update distance field if the graph is a grid graph, or if we are not sure which graph type it is
			var graphIndexProp = FindProperty("graphIndex");
			bool showField = true;
			if (!graphIndexProp.hasMultipleDifferentValues && AstarPath.active != null) {
				var graphIndex = graphIndexProp.intValue;
				if (graphIndex >= 0 && graphIndex < AstarPath.active.data.graphs.Length) {
					var graph = AstarPath.active.data.graphs[graphIndex];
					if (graph is GridGraph) {
						// NOOP
					} else if (graph is RecastGraph) {
						showField = false;
					} else {
						EditorGUILayout.HelpBox("The selected graph is not a grid, layered grid or recast graph", MessageType.Warning);
					}
				}
			}
			if (showField) {
				PropertyField("updateDistance");
			}
		}
	}
}