From 8722a9920c1f6119bf6e769cba270e63097f8e25 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Thu, 23 May 2024 10:08:29 +0800 Subject: + astar project --- .../Editor/ProceduralGridMoverEditor.cs | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Editor/ProceduralGridMoverEditor.cs (limited to 'Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Editor/ProceduralGridMoverEditor.cs') diff --git a/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Editor/ProceduralGridMoverEditor.cs b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Editor/ProceduralGridMoverEditor.cs new file mode 100644 index 0000000..4d125ef --- /dev/null +++ b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Editor/ProceduralGridMoverEditor.cs @@ -0,0 +1,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"); + } + } + } +} -- cgit v1.1-26-g67d0