Advertisement
rast

Astar gizmo patch

Apr 5th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. diff --git a/Assets/Code/AstarPathfindingProject/Core/astarclasses.cs b/Assets/Code/AstarPathfindingProject/Core/astarclasses.cs
  2. index 18592b1a..df9eb03c 100644
  3. --- a/Assets/Code/AstarPathfindingProject/Core/astarclasses.cs
  4. +++ b/Assets/Code/AstarPathfindingProject/Core/astarclasses.cs
  5. @@ -32,6 +32,7 @@ namespace Pathfinding {
  6. /// </summary>
  7. public Color[] _AreaColors;
  8.  
  9. + private static int? _hashTemp = null;
  10. public static Color SolidColor = new Color(30/255f, 102/255f, 201/255f, 0.9F);
  11. public static Color UnwalkableNode = new Color(1, 0, 0, 0.5F);
  12. public static Color BoundsHandles = new Color(0.29F, 0.454F, 0.741F, 0.9F);
  13. @@ -44,10 +45,17 @@ namespace Pathfinding {
  14. private static Color[] AreaColors = new Color[1];
  15.  
  16. public static int ColorHash () {
  17. + if (_hashTemp != null)
  18. + {
  19. + return _hashTemp.Value;
  20. + }
  21. var hash = SolidColor.GetHashCode() ^ UnwalkableNode.GetHashCode() ^ BoundsHandles.GetHashCode() ^ ConnectionLowLerp.GetHashCode() ^ ConnectionHighLerp.GetHashCode() ^ MeshEdgeColor.GetHashCode();
  22.  
  23. for (int i = 0; i < AreaColors.Length; i++) hash = 7*hash ^ AreaColors[i].GetHashCode();
  24. - return hash;
  25. +
  26. + _hashTemp = hash;
  27. +
  28. + return hash;
  29. }
  30.  
  31. /// <summary>
  32. @@ -86,7 +94,9 @@ namespace Pathfinding {
  33. ConnectionHighLerp = _ConnectionHighLerp;
  34. MeshEdgeColor = _MeshEdgeColor;
  35. AreaColors = _AreaColors;
  36. - }
  37. +
  38. + _hashTemp = null;
  39. + }
  40.  
  41. public AstarColor () {
  42. // Set default colors
  43. diff --git a/Assets/Code/AstarPathfindingProject/Generators/NavmeshBase.cs b/Assets/Code/AstarPathfindingProject/Generators/NavmeshBase.cs
  44. index e4cf9a4e..f9f52ebd 100644
  45. --- a/Assets/Code/AstarPathfindingProject/Generators/NavmeshBase.cs
  46. +++ b/Assets/Code/AstarPathfindingProject/Generators/NavmeshBase.cs
  47. @@ -1312,10 +1312,17 @@ namespace Pathfinding {
  48. // Update navmesh vizualizations for
  49. // the tiles that have been changed
  50. for (int i = 0; i < tiles.Length; i++) {
  51. - // This may happen if an exception has been thrown when the graph was scanned.
  52. - // We don't want the gizmo code to start to throw exceptions as well then as
  53. - // that would obscure the actual source of the error.
  54. - if (tiles[i] == null) continue;
  55. + Vector3 worldSpace = tiles[i].transform.InverseTransform(new Vector3(tiles[i].bbTree.Size.center.x, 0, tiles[i].bbTree.Size.center.y));
  56. + Vector3 screenSpace = Camera.current.WorldToScreenPoint(worldSpace);
  57. + if (screenSpace.x < 0
  58. + || screenSpace.y < 0
  59. + || screenSpace.x > Screen.width
  60. + || screenSpace.y > Screen.height) continue;
  61.  
  62. // Calculate a hash of the tile
  63. var hasher = new RetainedGizmos.Hasher(active);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement