summaryrefslogtreecommitdiff
path: root/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Editor/NavmeshCutEditor.cs
blob: 615d22e3da76d828376251ca7724d699e69d1d37 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using UnityEngine;
using UnityEditor;

namespace Pathfinding {
	[CustomEditor(typeof(NavmeshCut))]
	[CanEditMultipleObjects]
	public class NavmeshCutEditor : EditorBase {
		GUIContent[] MeshTypeOptions = new [] {
			new GUIContent("Rectangle (legacy)"),
			new GUIContent("Circle (legacy)"),
			new GUIContent("Custom Mesh"),
			new GUIContent("Box"),
			new GUIContent("Sphere"),
			new GUIContent("Capsule"),
		};

		protected override void Inspector () {
			// Make sure graphs are deserialized.
			// The gizmos on the navmesh cut uses the graph information to visualize the character radius
			AstarPath.FindAstarPath();

			EditorGUI.BeginChangeCheck();
			var type = FindProperty("type");
			var circleResolution = FindProperty("circleResolution");
			Popup("type", MeshTypeOptions, label: "Shape");
			EditorGUI.indentLevel++;

			if (!type.hasMultipleDifferentValues) {
				switch ((NavmeshCut.MeshType)type.intValue) {
				case NavmeshCut.MeshType.Circle:
				case NavmeshCut.MeshType.Capsule:
					FloatField("circleRadius", "Radius", min: 0.01f);
					PropertyField("circleResolution", "Resolution");
					FloatField("height", min: 0f);

					if (circleResolution.intValue >= 20) {
						EditorGUILayout.HelpBox("Be careful with large resolutions. It is often better with a relatively low resolution since it generates cleaner navmeshes with fewer nodes.", MessageType.Warning);
					}
					break;
				case NavmeshCut.MeshType.Sphere:
					FloatField("circleRadius", "Radius", min: 0.01f);
					PropertyField("circleResolution", "Resolution");

					if (circleResolution.intValue >= 20) {
						EditorGUILayout.HelpBox("Be careful with large resolutions. It is often better with a relatively low resolution since it generates cleaner navmeshes with fewer nodes.", MessageType.Warning);
					}
					break;
				case NavmeshCut.MeshType.Rectangle:
					PropertyField("rectangleSize");
					FloatField("height", min: 0f);
					break;
				case NavmeshCut.MeshType.Box:
					PropertyField("rectangleSize.x", "Width");
					PropertyField("height", "Height");
					PropertyField("rectangleSize.y", "Depth");
					break;
				case NavmeshCut.MeshType.CustomMesh:
					PropertyField("mesh");
					PropertyField("meshScale");
					FloatField("height", min: 0f);
					EditorGUILayout.HelpBox("This mesh should be a planar surface. Take a look at the documentation for an example.", MessageType.Info);
					break;
				}
			}

			PropertyField("center");
			EditorGUI.indentLevel--;

			EditorGUILayout.Separator();
			PropertyField("updateDistance");
			if (PropertyField("useRotationAndScale")) {
				EditorGUI.indentLevel++;
				FloatField("updateRotationDistance", min: 0f, max: 180f);
				EditorGUI.indentLevel--;
			}

			PropertyField("isDual");
			PropertyField("cutsAddedGeom", "Cuts Added Geometry");
			PropertyField("radiusExpansionMode", "Radius Expansion");

			EditorGUI.BeginChangeCheck();
			PropertyField("graphMask", "Affected Graphs");
			bool changedMask = EditorGUI.EndChangeCheck();

			serializedObject.ApplyModifiedProperties();

			if (EditorGUI.EndChangeCheck()) {
				foreach (NavmeshCut tg in targets) {
					tg.ForceUpdate();
					// If the mask is changed we disable and then enable the component
					// to make sure it is removed from the right graphs and then added back
					if (changedMask && tg.enabled) {
						tg.enabled = false;
						tg.enabled = true;
					}
				}
			}
		}
	}
}