Advertisement
Guest User

Untitled

a guest
May 10th, 2013
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using DeenGames.Utils;
  4. using DeenGames.Utils.AStarPathFinder;
  5.  
  6. public class PfExample {
  7.  
  8. public int size = 8;
  9. byte[,] grid;
  10. PathFinder pf;
  11.  
  12. void Start () {
  13. grid = new byte[size, size];
  14.  
  15. for (int i = 0; i < size; i++) {
  16. for (int j= 0; j < size; j++) {
  17. grid[i, j] = PathFinderHelper.EMPTY_TILE;
  18. }
  19. }
  20.  
  21. grid[1, 0] = PathFinderHelper.BLOCKED_TILE;
  22.  
  23. GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
  24. cube.transform.position = new Vector3(1*5, 0, 0);
  25. cube.transform.localScale = new Vector3(4, 4, 4);
  26.  
  27. grid[1, 1] = PathFinderHelper.BLOCKED_TILE;
  28. grid[3, 1] = PathFinderHelper.BLOCKED_TILE;
  29. grid[4, 2] = PathFinderHelper.BLOCKED_TILE;
  30.  
  31. pf = new PathFinder(grid);
  32. pf.Diagonals = false;
  33. }
  34.  
  35. void Update () {
  36. if(Input.GetKeyDown(KeyCode.A))
  37. {
  38. GetPath(new Point(0, 0), new Point(4, 0));
  39. }
  40. }
  41.  
  42. void GetPath(Point from, Point to) {
  43. List<PathFinderNode> path = pf.FindPath(from, to);
  44. if (path != null) {
  45. Debug.Log ("Found path " + path.Count);
  46.  
  47. foreach(PathFinderNode node in path)
  48. {
  49. Debug.Log (node.PX+ "x" + node.PY);
  50. }
  51. }
  52. else
  53. {
  54. Debug.Log ("No path");
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement