diff options
author | chai <215380520@qq.com> | 2024-05-23 10:08:29 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2024-05-23 10:08:29 +0800 |
commit | 8722a9920c1f6119bf6e769cba270e63097f8e25 (patch) | |
tree | 2eaf9865de7fb1404546de4a4296553d8f68cc3b /Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Navmesh/NavmeshClipper.cs | |
parent | 3ba4020b69e5971bb0df7ee08b31d10ea4d01937 (diff) |
+ astar project
Diffstat (limited to 'Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Navmesh/NavmeshClipper.cs')
-rw-r--r-- | Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Navmesh/NavmeshClipper.cs | 75 |
1 files changed, 75 insertions, 0 deletions
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; + + /// <summary>Base class for the NavmeshCut and NavmeshAdd components</summary> + [ExecuteAlways] + public abstract class NavmeshClipper : VersionedMonoBehaviour { + /// <summary>Called every time a NavmeshCut/NavmeshAdd component is enabled.</summary> + static System.Action<NavmeshClipper> OnEnableCallback; + + /// <summary>Called every time a NavmeshCut/NavmeshAdd component is disabled.</summary> + static System.Action<NavmeshClipper> OnDisableCallback; + + static readonly List<NavmeshClipper> all = new List<NavmeshClipper>(); + int listIndex = -1; + + /// <summary> + /// 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: <see cref="NavmeshBase.enableNavmeshCutting"/> + /// </summary> + public GraphMask graphMask = GraphMask.everything; + + public static void AddEnableCallback (System.Action<NavmeshClipper> onEnable, System.Action<NavmeshClipper> onDisable) { + OnEnableCallback += onEnable; + OnDisableCallback += onDisable; + } + + public static void RemoveEnableCallback (System.Action<NavmeshClipper> onEnable, System.Action<NavmeshClipper> onDisable) { + OnEnableCallback -= onEnable; + OnDisableCallback -= onDisable; + } + + /// <summary> + /// All navmesh clipper components in the scene. + /// Not ordered in any particular way. + /// Warning: Do not modify this list + /// </summary> + public static List<NavmeshClipper> 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<NavmeshClipper>.Root previousState); + public abstract Rect GetBounds(GraphTransform transform, float radiusMargin); + public abstract bool RequiresUpdate(GridLookup<NavmeshClipper>.Root previousState); + public abstract void ForceUpdate(); + } +} |