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(); } }