Пример #1
0
        //Switch to next node.
        void GetNextNode()
        {
            openList = openList.OrderBy(x => x.fCost).ToList();

            currentNode = openList.FirstOrDefault();
            closedList.Add(currentNode);
            openList.RemoveAt(0);
        }
Пример #2
0
 void ValidateAndAddNode(GridNode node, ref List<GridPathNode> nodes)
 {
     GridPathNode pathNode;
     if (!closedList.Any(x => x.node == node) && node.NodeIsValid())
     {
         pathNode = new GridPathNode(node);
         nodes.Add(pathNode);
         pathNode.parent = currentNode;
         pathNode.CalculateCosts(target);
     }
 }
Пример #3
0
 //Builds final path.
 void BuildPath()
 {
     GridPathNode node = openList.Single(x => x.node == target);
     while (node.parent != null)
     {
         finalPath.Add(node);
         node = node.parent;
     }
     finalPath.Reverse();
     nodePath = finalPath.Select(x => x.node).ToList();
 }
Пример #4
0
 void OnDrawGizmos()
 {
     Gizmos.color = Color.blue;
     for (int i = path.Count - 1; i > 0; i--)
     {
         GridPathNode node = finalPath[i];
         if (node.parent != null)
         {
             Gizmos.DrawLine(node.block.position, node.parent.block.position);
         }
     }
 }