Esempio n. 1
0
    // Start Pathfinding from Start to Goal tile
    public bool StartPathfinding()
    {
        Debug.Log("Start Path Finding");

        if (World.startTile == null || World.goalTile == null)
        {
            Debug.LogError("No Start or Goal tile");
            return(false);
        }

        Path_AStar oldPathAStar = pathAStar;

        // Update old path way not valid anymore
        if (oldPathAStar != null)
        {
            foreach (Tile t in oldPathAStar.Path())
            {
                //Debug.Log("Old Path:"+ tileGraphicController.tileGameObjectMap[t] );
                t.isPathway = false;
                tileGraphicController.tileGameObjectMap[t].GetComponent <GroundCube>().UpdatePathfindingGraphic();
            }
        }
        // Generate New pathway
        pathAStar = new Path_AStar(true, World.startTile, World.goalTile);
        if (pathAStar.Length() == 0)
        {
            // No valid Pathfinding way
            Debug.LogError("Path_AStar returned no path to destination!");
            pathAStar = null;
            return(false);
        }
        else
        {
            foreach (Tile t in pathAStar.Path())
            {
                t.isPathway = true;
                tileGraphicController.tileGameObjectMap[t].GetComponent <GroundCube>().UpdatePathfindingGraphic();
            }
            return(true);
        }
    }