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/NavmeshClipper.cs | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Navmesh/NavmeshClipper.cs (limited to 'Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Navmesh/NavmeshClipper.cs') diff --git a/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Navmesh/NavmeshClipper.cs b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Navmesh/NavmeshClipper.cs new file mode 100644 index 0000000..3dc0cca --- /dev/null +++ b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Navmesh/NavmeshClipper.cs @@ -0,0 +1,75 @@ +namespace Pathfinding { + using Pathfinding.Util; + using Pathfinding.Graphs.Util; + using UnityEngine; + using System.Collections.Generic; + + /// Base class for the NavmeshCut and NavmeshAdd components + [ExecuteAlways] + public abstract class NavmeshClipper : VersionedMonoBehaviour { + /// Called every time a NavmeshCut/NavmeshAdd component is enabled. + static System.Action OnEnableCallback; + + /// Called every time a NavmeshCut/NavmeshAdd component is disabled. + static System.Action OnDisableCallback; + + static readonly List all = new List(); + int listIndex = -1; + + /// + /// Which graphs that are affected by this component. + /// + /// You can use this to make a graph ignore a particular navmesh cut altogether. + /// + /// Note that navmesh cuts can only affect navmesh/recast graphs. + /// + /// If you change this field during runtime you must disable the component and enable it again for the changes to be detected. + /// + /// See: + /// + public GraphMask graphMask = GraphMask.everything; + + public static void AddEnableCallback (System.Action onEnable, System.Action onDisable) { + OnEnableCallback += onEnable; + OnDisableCallback += onDisable; + } + + public static void RemoveEnableCallback (System.Action onEnable, System.Action onDisable) { + OnEnableCallback -= onEnable; + OnDisableCallback -= onDisable; + } + + /// + /// All navmesh clipper components in the scene. + /// Not ordered in any particular way. + /// Warning: Do not modify this list + /// + public static List allEnabled { get { return all; } } + + protected virtual void OnEnable () { + if (!Application.isPlaying) return; + + if (OnEnableCallback != null) OnEnableCallback(this); + listIndex = all.Count; + all.Add(this); + } + + protected virtual void OnDisable () { + if (!Application.isPlaying) return; + + // Efficient removal (the list doesn't need to be ordered). + // Move the last item in the list to the slot occupied by this item + // and then remove the last slot. + all[listIndex] = all[all.Count-1]; + all[listIndex].listIndex = listIndex; + all.RemoveAt(all.Count-1); + listIndex = -1; + if (OnDisableCallback != null) OnDisableCallback(this); + } + + internal abstract void NotifyUpdated(GridLookup.Root previousState); + public abstract Rect GetBounds(GraphTransform transform, float radiusMargin); + public abstract bool RequiresUpdate(GridLookup.Root previousState); + public abstract void ForceUpdate(); + } +} -- cgit v1.1-26-g67d0