summaryrefslogtreecommitdiff
path: root/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Editor/NavmeshCutEditor.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2024-05-23 10:08:29 +0800
committerchai <215380520@qq.com>2024-05-23 10:08:29 +0800
commit8722a9920c1f6119bf6e769cba270e63097f8e25 (patch)
tree2eaf9865de7fb1404546de4a4296553d8f68cc3b /Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Editor/NavmeshCutEditor.cs
parent3ba4020b69e5971bb0df7ee08b31d10ea4d01937 (diff)
+ astar project
Diffstat (limited to 'Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Editor/NavmeshCutEditor.cs')
-rw-r--r--Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Editor/NavmeshCutEditor.cs100
1 files changed, 100 insertions, 0 deletions
diff --git a/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Editor/NavmeshCutEditor.cs b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Editor/NavmeshCutEditor.cs
new file mode 100644
index 0000000..615d22e
--- /dev/null
+++ b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Editor/NavmeshCutEditor.cs
@@ -0,0 +1,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;
+ }
+ }
+ }
+ }
+ }
+}