summaryrefslogtreecommitdiff
path: root/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/ExampleScripts/RecastTileUpdate.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/ExampleScenes/ExampleScripts/RecastTileUpdate.cs
parent3ba4020b69e5971bb0df7ee08b31d10ea4d01937 (diff)
+ astar project
Diffstat (limited to 'Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/ExampleScripts/RecastTileUpdate.cs')
-rw-r--r--Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/ExampleScripts/RecastTileUpdate.cs50
1 files changed, 50 insertions, 0 deletions
diff --git a/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/ExampleScripts/RecastTileUpdate.cs b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/ExampleScripts/RecastTileUpdate.cs
new file mode 100644
index 0000000..2153625
--- /dev/null
+++ b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/ExampleScripts/RecastTileUpdate.cs
@@ -0,0 +1,50 @@
+using UnityEngine;
+
+namespace Pathfinding {
+ /// <summary>
+ /// Updates the recast tile(s) it is in at start, needs RecastTileUpdateHandler.
+ ///
+ /// If there is a collider attached to the same GameObject, the bounds
+ /// of that collider will be used for updating, otherwise
+ /// only the position of the object will be used.
+ ///
+ /// Note: This class needs a RecastTileUpdateHandler somewhere in the scene.
+ /// See the documentation for that class, it contains more information.
+ ///
+ /// Note: This does not use navmesh cutting. If you only ever add
+ /// obstacles, but never add any new walkable surfaces then you might
+ /// want to use navmesh cutting instead. See navmeshcutting (view in online documentation for working links).
+ ///
+ /// See: RecastTileUpdateHandler
+ ///
+ /// Deprecated: Since version 5.0, this component is not necessary, since normal graph updates on recast graphs are now batched together if they update the same tiles.
+ /// Use e.g. the <see cref="DynamicGridObstacle"/> component instead.
+ /// </summary>
+ [HelpURL("https://arongranberg.com/astar/documentation/stable/recasttileupdate.html")]
+ public class RecastTileUpdate : MonoBehaviour {
+ public static event System.Action<Bounds> OnNeedUpdates;
+
+ void Start () {
+ ScheduleUpdate();
+ }
+
+ void OnDestroy () {
+ ScheduleUpdate();
+ }
+
+ /// <summary>Schedule a tile update for all tiles that contain this object</summary>
+ public void ScheduleUpdate () {
+ var collider = GetComponent<Collider>();
+
+ if (collider != null) {
+ if (OnNeedUpdates != null) {
+ OnNeedUpdates(collider.bounds);
+ }
+ } else {
+ if (OnNeedUpdates != null) {
+ OnNeedUpdates(new Bounds(transform.position, Vector3.zero));
+ }
+ }
+ }
+ }
+}