Esempio n. 1
0
    public List <Node <Tile> > ConstructPath(Tile start, Tile goal)
    {
        if (Nodes.ContainsKey(start) && Nodes.ContainsKey(goal))
        {
            List <Node <Tile> > nodeList = AStar.ConstructPath(
                Nodes[start],
                Nodes[goal],
                (node) =>
            {
                return((node.Data.NodeTransform.position -
                        goal.NodeTransform.position).sqrMagnitude);
            }
                );

            if (nodeList != null)
            {
                /*List<Vector2Int> path = new List<Vector2Int>();
                 * foreach (var node in nodeList)
                 * {
                 *  path.Add(node.Data.Position);
                 * }*/
                return(nodeList);
            }
            else // Error
            {
                Debug.LogError("A* failed to return a valid path.");
                return(null);
            }
        }
        else // Error
        {
            if (!Nodes.ContainsKey(start))
            {
                if (DebugLog)
                {
                    Debug.LogError("Start tile has no assigned node.");
                }
            }
            if (!Nodes.ContainsKey(goal))
            {
                if (DebugLog)
                {
                    Debug.LogError("Goal tile has no assigned node.");
                }
            }
            return(null);
        }
    }