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
---
.../Navmesh/RelevantGraphSurface.cs | 94 ++++++++++++++++++++++
1 file changed, 94 insertions(+)
create mode 100644 Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Navmesh/RelevantGraphSurface.cs
(limited to 'Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Navmesh/RelevantGraphSurface.cs')
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;
+
+ ///
+ /// 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
+ ///
+ [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;
+ }
+
+ ///
+ /// Updates the positions of all relevant graph surface components.
+ /// Required to be able to use the position property reliably.
+ ///
+ public static void UpdateAllPositions () {
+ RelevantGraphSurface c = root;
+
+ while (c != null) { c.UpdatePosition(); c = c.Next; }
+ }
+
+ public static void FindAllGraphSurfaces () {
+ var srf = UnityCompatibility.FindObjectsByTypeUnsorted();
+
+ 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);
+ }
+ }
+}
--
cgit v1.1-26-g67d0