summaryrefslogtreecommitdiff
path: root/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Navmesh/RelevantGraphSurface.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/Navmesh/RelevantGraphSurface.cs
parent3ba4020b69e5971bb0df7ee08b31d10ea4d01937 (diff)
+ astar project
Diffstat (limited to 'Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Navmesh/RelevantGraphSurface.cs')
-rw-r--r--Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Navmesh/RelevantGraphSurface.cs94
1 files changed, 94 insertions, 0 deletions
diff --git a/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Navmesh/RelevantGraphSurface.cs b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Navmesh/RelevantGraphSurface.cs
new file mode 100644
index 0000000..c2cc553
--- /dev/null
+++ b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Navmesh/RelevantGraphSurface.cs
@@ -0,0 +1,94 @@
+using UnityEngine;
+
+namespace Pathfinding.Graphs.Navmesh {
+ using Pathfinding.Drawing;
+ using Pathfinding.Util;
+
+ /// <summary>
+ /// Pruning of recast navmesh regions.
+ /// A RelevantGraphSurface component placed in the scene specifies that
+ /// the navmesh region it is inside should be included in the navmesh.
+ ///
+ /// See: Pathfinding.RecastGraph.relevantGraphSurfaceMode
+ /// </summary>
+ [AddComponentMenu("Pathfinding/Navmesh/RelevantGraphSurface")]
+ [HelpURL("https://arongranberg.com/astar/documentation/stable/relevantgraphsurface.html")]
+ public class RelevantGraphSurface : VersionedMonoBehaviour {
+ private static RelevantGraphSurface root;
+
+ public float maxRange = 1;
+
+ private RelevantGraphSurface prev;
+ private RelevantGraphSurface next;
+ private Vector3 position;
+
+ public Vector3 Position {
+ get { return position; }
+ }
+
+ public RelevantGraphSurface Next {
+ get { return next; }
+ }
+
+ public RelevantGraphSurface Prev {
+ get { return prev; }
+ }
+
+ public static RelevantGraphSurface Root {
+ get { return root; }
+ }
+
+ public void UpdatePosition () {
+ position = transform.position;
+ }
+
+ void OnEnable () {
+ UpdatePosition();
+ if (root == null) {
+ root = this;
+ } else {
+ next = root;
+ root.prev = this;
+ root = this;
+ }
+ }
+
+ void OnDisable () {
+ if (root == this) {
+ root = next;
+ if (root != null) root.prev = null;
+ } else {
+ if (prev != null) prev.next = next;
+ if (next != null) next.prev = prev;
+ }
+ prev = null;
+ next = null;
+ }
+
+ /// <summary>
+ /// Updates the positions of all relevant graph surface components.
+ /// Required to be able to use the position property reliably.
+ /// </summary>
+ public static void UpdateAllPositions () {
+ RelevantGraphSurface c = root;
+
+ while (c != null) { c.UpdatePosition(); c = c.Next; }
+ }
+
+ public static void FindAllGraphSurfaces () {
+ var srf = UnityCompatibility.FindObjectsByTypeUnsorted<RelevantGraphSurface>();
+
+ for (int i = 0; i < srf.Length; i++) {
+ srf[i].OnDisable();
+ srf[i].OnEnable();
+ }
+ }
+
+ public override void DrawGizmos () {
+ var color = new Color(57/255f, 211/255f, 46/255f);
+
+ if (!GizmoContext.InActiveSelection(this)) color.a *= 0.4f;
+ Draw.Line(transform.position - Vector3.up*maxRange, transform.position + Vector3.up*maxRange, color);
+ }
+ }
+}