/// <summary> /// 将这个点的周围都加入到开放合集; /// </summary> void OpenNeighbors(PathNode parent) { var neighbors = parent.Position.GetNeighbours(); foreach (var neighbor in neighbors) { if (!closePointsSet.Contains(neighbor)) { PathNode neighborNode; if (IsOutRange(neighbor)) { closePointsSet.Add(neighbor); } else if (openPointsSet.TryGetValue(neighbor, out neighborNode)) { neighborNode.TryChangeParent(parent); } else if (!Walker.IsWalkable(neighbor)) { closePointsSet.Add(neighbor); } else { int cost = Walker.GetCost(parent.Position, neighbor, Destination); neighborNode = new PathNode(parent, neighbor, cost); openPointsSet.Add(neighborNode); } } } }