private IEnumerator CalculateMeshOutlines() { for (int vertexIndex = 0; vertexIndex < vertices.Count; vertexIndex++) { if (!checkedVertices.Contains(vertexIndex)) { int newOutlineVertex = GetConnectedOutlineVertex(vertexIndex); if (newOutlineVertex != -1) { checkedVertices.Add(vertexIndex); List <int> newOutline = new List <int> { vertexIndex }; outlines.Add(newOutline); FollowOutline(newOutlineVertex, outlines.Count - 1); outlines[outlines.Count - 1].Add(vertexIndex); } } if (CorutineUtilities.WaitAmountOfTimes(vertexIndex, vertices.Count, 30)) { yield return(Wait("Calculating mesh outlines")); } } }
protected IEnumerator ConnectRooms(List <Room> roomsA, List <Room> roomsB) { bool possibleConnectionEstablished = false; bool isForcingStartAccesibility = !roomsA.Equals(roomsB); Room bestRoomA = null, bestRoomB = null; Coordinate bestTileA = new Coordinate(), bestTileB = new Coordinate(); int closestDistance = 0, roomCheckFrequency = 4; foreach (Room roomA in roomsA) { if (!isForcingStartAccesibility) { possibleConnectionEstablished = false; if (roomA.ConnectedRooms.Count > 0) { continue; } } foreach (Room roomB in roomsB) { if (roomA == roomB || roomA.IsConnected(roomB)) { continue; } for (int tileIndexA = 0; tileIndexA < roomA.EdgeTiles.Count; tileIndexA++) { if (tileIndexA % roomCheckFrequency != 0) { continue; } for (int tileIndexB = 0; tileIndexB < roomB.EdgeTiles.Count; tileIndexB++) { if (tileIndexB % roomCheckFrequency != 0) { continue; } Coordinate tileA = roomA.EdgeTiles[tileIndexA]; Coordinate tileB = roomB.EdgeTiles[tileIndexB]; int distanceBetweenRooms = (int)(Mathf.Pow(tileA.TileX - tileB.TileX, 2) + Mathf.Pow(tileA.TileY - tileB.TileY, 2)); if (distanceBetweenRooms < closestDistance || !possibleConnectionEstablished) { closestDistance = distanceBetweenRooms; possibleConnectionEstablished = true; bestTileA = tileA; bestTileB = tileB; bestRoomB = roomA; bestRoomA = roomB; } } if (CorutineUtilities.WaitAmountOfTimes(tileIndexA, roomA.EdgeTiles.Count, 10)) { yield return(Wait("Finding closest tiles")); } } } if (possibleConnectionEstablished && !isForcingStartAccesibility) { CreatePassage(bestRoomA, bestRoomB, bestTileA, bestTileB); } } if (possibleConnectionEstablished && isForcingStartAccesibility) { CreatePassage(bestRoomA, bestRoomB, bestTileA, bestTileB); List <Room> rooms = roomsA.Union(roomsB).ToList(); yield return(StartCoroutine(ConnectAllRooms(rooms, true))); } }