RecastTileUpdate.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using UnityEngine;
  2. namespace Pathfinding {
  3. /// <summary>
  4. /// Updates the recast tile(s) it is in at start, needs RecastTileUpdateHandler.
  5. ///
  6. /// If there is a collider attached to the same GameObject, the bounds
  7. /// of that collider will be used for updating, otherwise
  8. /// only the position of the object will be used.
  9. ///
  10. /// Note: This class needs a RecastTileUpdateHandler somewhere in the scene.
  11. /// See the documentation for that class, it contains more information.
  12. ///
  13. /// Note: This does not use navmesh cutting. If you only ever add
  14. /// obstacles, but never add any new walkable surfaces then you might
  15. /// want to use navmesh cutting instead. See navmeshcutting (view in online documentation for working links).
  16. ///
  17. /// See: RecastTileUpdateHandler
  18. /// </summary>
  19. [AddComponentMenu("Pathfinding/Navmesh/RecastTileUpdate")]
  20. [HelpURL("http://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_recast_tile_update.php")]
  21. public class RecastTileUpdate : MonoBehaviour {
  22. public static event System.Action<Bounds> OnNeedUpdates;
  23. void Start () {
  24. ScheduleUpdate();
  25. }
  26. void OnDestroy () {
  27. ScheduleUpdate();
  28. }
  29. /// <summary>Schedule a tile update for all tiles that contain this object</summary>
  30. public void ScheduleUpdate () {
  31. var collider = GetComponent<Collider>();
  32. if (collider != null) {
  33. if (OnNeedUpdates != null) {
  34. OnNeedUpdates(collider.bounds);
  35. }
  36. } else {
  37. if (OnNeedUpdates != null) {
  38. OnNeedUpdates(new Bounds(transform.position, Vector3.zero));
  39. }
  40. }
  41. }
  42. }
  43. }