//High level description
Create two list
InterestionsList (this only hold points and lines)
CreatedRoadList (this list hold the mesh or we can say this list hold the lines that already been created from InterestionsList)
loop through InterestionsList and every item in InterestionList create a intersection
get all the lines that are connected to that intersection
check has the lines been create if not then create the road and connect the road to the intersection
else just connect the road to the intersection
List<Interestion> InterestionsList;
List<CreatedRoad> CreatedRoadList;
void CreateInterestion(List<Interestion> inters , int connectedroad)
{
//build mesh
}
void buildroad(float startX , float startY , float EndX , float EndY)
{
// build mesh base on the input value
}
void ConnectInterstion(Mesh m , Lines line)
{
Road road = new Road();
//connect intersection and the road base on the road dir and position
CreatedRoadList.Add(road);
}
void Update()
{
for(int i= 0 ; i< i<InterestionsList.count(); i++)
{
InterestionsList[i].getPosition();
Lines[] lines = InterestionsList[i].getConnectLine();
CreateInterestion(InterestionsList[i].getPosition() , lines.count)
for(int i= 0 ; i< i<lines.count(); i++)
{
for(int j =0 ; j<CreatedRoadList.count(); j++ )
{
if(lines.ID == CreatedRoadList[i].ID)
{
ConnectInterstion(m, Lines[i]);
break;
}
else
{
Mesh m = buildroad(Lines[i].Start.x, Lines[i].Start.y ,Lines[i].End.x,Lines[i].End.y);
ConnectInterstion(m, Lines[i]);
}
}
}
}
}