LocalSpaceGraph.cs 793 B

12345678910111213141516171819202122232425
  1. using UnityEngine;
  2. namespace Pathfinding {
  3. using Pathfinding.Util;
  4. /// <summary>Helper for <see cref="Pathfinding.Examples.LocalSpaceRichAI"/></summary>
  5. [HelpURL("http://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_local_space_graph.php")]
  6. public class LocalSpaceGraph : VersionedMonoBehaviour {
  7. Matrix4x4 originalMatrix;
  8. public GraphTransform transformation { get; private set; }
  9. void Start () {
  10. originalMatrix = transform.worldToLocalMatrix;
  11. transform.hasChanged = true;
  12. Refresh();
  13. }
  14. public void Refresh () {
  15. // Avoid updating the GraphTransform if the object has not moved
  16. if (transform.hasChanged) {
  17. transformation = new GraphTransform(transform.localToWorldMatrix * originalMatrix);
  18. transform.hasChanged = false;
  19. }
  20. }
  21. }
  22. }