示例#1
0
    /// <summary>
    /// Checks if the path is ready to be found.
    /// </summary>
    private void CheckIfPathReady()
    {
        if (StartNode != null && GoalNode != null)
        {
            // Pathfinding
            List <ButtonNode> pathNodes = pathfinder.FindPath();

            // If the path is found
            if (!(pathNodes is null))
            {
                // Set up the path buttons
                for (int i = 0; i < pathNodes.Count; i++)
                {
                    ButtonInfo pathButton = ButtonPool.sharedInstance.GetPooledButton(pathNodes[i].X - 1, pathNodes[i].Y - 1);
                    pathButton.IsPath(true, pathNodes[i].DistanceFromStart);
                    pathButtons.Add(pathButton);
                }

                // Adjust the text of the start and goal buttons
                StartNode.AddDistanceText(0);
                int goalNodeDistance = pathNodes[0].DistanceFromStart + 1;
                GoalNode.AddDistanceText(goalNodeDistance);
            }
            else
            {
                Debug.Log("Could not find a path to the goal.");
            }
        }