Esempio n. 1
0
    private void Set(PathNode node)
    {
        openList.Remove(node);
        closedList.Add(node);
        PathNode newNode;

        foreach (Coords node_nb in node.node.neighbours)
        {
            Environment.Node neighbour = Environment.instance[node_nb.x, node_nb.y];
            if (closedListContains(node_nb) != -1)
            {
                continue;
            }
            int index = openListContains(node_nb); //add neighbours to open list
            if (index == -1)
            {
                newNode = new PathNode(neighbour, node, targetNode.coords);
                openList.Add(newNode);
                if (Equals(neighbour, targetNode))
                {
                    foundTarget = true; break;
                }                                                                 //check if it is destination
            }
            else //repartent if needed
            {
                if (openList[index].gValue > node.gValue + node.movementCost(node.node.coords, openList[index].node.coords))
                {
                    newNode         = new PathNode(openList[index].node, node, targetNode.coords);
                    openList[index] = newNode;
                }
            }
        }
    }
Esempio n. 2
0
 public PathNode(Environment.Node node, PathNode parent, Coords target)
 {
     this.node   = node;
     this.parent = parent;
     if (parent != null)
     {
         this.gValue = movementCost(node.coords, parent.node.coords);
     }
     else
     {
         gValue = 0;
     }
     hValue = Mathf.Abs(target.x - node.coords.x) + Mathf.Abs(target.y - node.coords.y);
 }
Esempio n. 3
0
 private void show()
 {
     foreach (Environment.Node nd in Environment.instance)
     {
         GameObject d;
         try {
             d = new GameObject("node: " + nd.coords.x + "," + nd.coords.y);
         } catch (NullReferenceException e) { continue; }
         d.transform.position = nd.worldLocation;
         byte x = 0;
         foreach (Coords nbCoords in nd.neighbours)
         {
             Environment.Node nb = Environment.instance[nbCoords.x, nbCoords.y];
             var c = new GameObject("nb: " + nb.coords.x + "," + nb.coords.y + " dir: " + nd.direction[x]);
             c.transform.position = nb.worldLocation;
             c.transform.SetParent(d.transform);
             x++;
         }
     }
 }
Esempio n. 4
0
 public Pathfinding(Vector2 from, Vector2 to, MonoBehaviour a)
 {
     startNode = Environment.Position2Node(from);
     targetNode = Environment.Position2Node(to);
     Start();
 }
Esempio n. 5
0
 public PathNode(Environment.Node node, PathNode parent, Coords target)
 {
     this.node = node;
     this.parent = parent;
     if (parent != null)
         this.gValue = movementCost(node.coords, parent.node.coords);
     else
         gValue = 0;
     hValue = Mathf.Abs(target.x - node.coords.x)+Mathf.Abs(target.y - node.coords.y);
 }
Esempio n. 6
0
 public Pathfinding(Vector2 from, Vector2 to, MonoBehaviour a)
 {
     startNode  = Environment.Position2Node(from);
     targetNode = Environment.Position2Node(to);
     Start();
 }
Esempio n. 7
0
 private bool Equals(Environment.Node a, Environment.Node b)
 {
     return(a.coords.x == b.coords.x && a.coords.y == b.coords.y);
 }