Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using DeenGames.Utils;
- using DeenGames.Utils.AStarPathFinder;
- public class PfExample {
- public int size = 8;
- byte[,] grid;
- PathFinder pf;
- void Start () {
- grid = new byte[size, size];
- for (int i = 0; i < size; i++) {
- for (int j= 0; j < size; j++) {
- grid[i, j] = PathFinderHelper.EMPTY_TILE;
- }
- }
- grid[1, 0] = PathFinderHelper.BLOCKED_TILE;
- GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
- cube.transform.position = new Vector3(1*5, 0, 0);
- cube.transform.localScale = new Vector3(4, 4, 4);
- grid[1, 1] = PathFinderHelper.BLOCKED_TILE;
- grid[3, 1] = PathFinderHelper.BLOCKED_TILE;
- grid[4, 2] = PathFinderHelper.BLOCKED_TILE;
- pf = new PathFinder(grid);
- pf.Diagonals = false;
- }
- void Update () {
- if(Input.GetKeyDown(KeyCode.A))
- {
- GetPath(new Point(0, 0), new Point(4, 0));
- }
- }
- void GetPath(Point from, Point to) {
- List<PathFinderNode> path = pf.FindPath(from, to);
- if (path != null) {
- Debug.Log ("Found path " + path.Count);
- foreach(PathFinderNode node in path)
- {
- Debug.Log (node.PX+ "x" + node.PY);
- }
- }
- else
- {
- Debug.Log ("No path");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement