void IUpdatable.update() { // on left click set our path end time if (Input.leftMouseButtonPressed) { _end = _tilemap.worldToTilePosition(Input.mousePosition); } // on right click set our path start time if (Input.rightMouseButtonPressed) { _start = _tilemap.worldToTilePosition(Input.mousePosition); } // regenerate the path on either click if (Input.leftMouseButtonPressed || Input.rightMouseButtonPressed) { // time both path generations var first = Debug.timeAction(() => { _breadthSearchPath = _gridGraph.search(_start, _end); }); var second = Debug.timeAction(() => { _astarSearchPath = _astarGraph.search(_start, _end); }); // debug draw the times Debug.drawText("Breadth First: {0}\nAstar: {1}", first, second); } }
public Pathfinder(TiledMap tilemap) { _tilemap = tilemap; var layer = tilemap.getLayer <TiledTileLayer>("main"); _start = new Point(1, 1); _end = new Point(10, 10); _gridGraph = new UnweightedGridGraph(layer); _breadthSearchPath = _gridGraph.search(_start, _end); _astarGraph = new WeightedGridGraph(layer); _astarSearchPath = _astarGraph.search(_start, _end); Debug.drawTextFromBottom = true; }