Esempio n. 1
0
        public void LoadRiver(Tilemap mainTilemap)
        {
            var grid = new List <List <Node> >();

            for (int i = bottomLeftCorner.x - 5; i < upperRightCorner.x + 5; i++)
            {
                var row = new List <Node>();
                for (int j = bottomLeftCorner.y - 5; j < upperRightCorner.y + 5; j++)
                {
                    row.Add(MakeMapNode(new Vector2Int(i, j)));
                }
                grid.Add(row);
            }
            var astar = new Astar(grid);

            var start = -castleTemplate.boundingBox.size / 2 - bottomLeftCorner + new Vector2Int(5, 5);
            var end   = new Vector2Int(1, 1);

            var pathStack = astar.FindPath(start, end);

            if (pathStack != null)
            {
                foreach (var item in pathStack)
                {
                    var pos = item.Position + bottomLeftCorner - new Vector2Int(5, 5);
                    mainTilemap.SetTile(pos.To3D(), riverTile);
                }
            }

            start = castleTemplate.boundingBox.size / 2 - bottomLeftCorner + new Vector2Int(4, 4);
            end   = usableMapDimensions + new Vector2Int(8, 8);

            pathStack = astar.FindPath(start, end);
            if (pathStack != null)
            {
                foreach (var item in pathStack)
                {
                    var pos = item.Position + bottomLeftCorner - new Vector2Int(5, 5);
                    mainTilemap.SetTile(pos.To3D(), riverTile);
                }
            }
        }
Esempio n. 2
0
    Vector2 pathfind(Vector2 myPos, Vector2 otherPos)
    {
        Stack <AStarSharp.Node> temp = pathfindAstar.FindPath(new Vector2(myPos.x / 16, myPos.y / 16), new Vector2(otherPos.x, otherPos.y));

        return(temp.Pop().Position);
    }