Ejemplo n.º 1
0
 // Use DFS, because it's easy to implement :D
 void FindPath(GameObject origin, GameObject destination, ref Stack <GameObject> path, ref bool found)
 {
     if (found)
     {
         return;
     }
     foreach (GameObject neighbor in origin.GetComponent <IsometricTile>().m_adjacent)
     {
         if (neighbor != null)
         {
             if (neighbor == destination)
             {
                 path.Push(destination);
                 found = true;
                 return;
             }
             else if (neighbor.GetComponent <SpriteRenderer>().sprite == m_tileSelector.m_destination && !path.Contains(neighbor))
             {
                 path.Push(origin);
                 FindPath(neighbor, destination, ref path, ref found);
             }
         }
     }
     foreach (GameObject road in m_tileSelector.AdjacentRoads(origin.GetComponent <IsometricTile>()))
     {
         if (!path.Contains(road))
         {
             path.Push(origin);
             FindPath(road, destination, ref path, ref found);
         }
     }
     path.Pop();
 }