[SerializeField] private float bias; //How far from the centre should the connection point spawn the next room? public IEnumerator GenerateRoom() { int generatedProb = Random.Range(0, spawnRooms.Length); GameObject roomToGenerate = spawnRooms[generatedProb]; Quaternion rotation = Quaternion.LookRotation(this.transform.forward); Vector3 position = GenerateRelativeVector(rotation.eulerAngles.y, bias); GameObject generatedRoom = Instantiate(roomToGenerate, position, rotation); yield return(null); TestConnection[] TestConnections = generatedRoom.GetComponentsInChildren <TestConnection>(); CheckCollision validatorNewRoom = generatedRoom.GetComponentInChildren <CheckCollision>(); TestConnection chosenPoint = TestConnections[0]; validatorNewRoom.TurnOnCollider(); yield return(new WaitForSeconds(0.05f)); if (validatorNewRoom.GetIsCollided()) { Destroy(generatedRoom); yield return(null); } else { TestMapGen.AddGeneratedRoom(generatedRoom); this.SetConnected(); chosenPoint.SetConnected(); TestMapGen.AddTestConnections(TestConnections); } }
[SerializeField] private float bias; //How far from the centre should the connection point spawn the next room? public IEnumerator GenerateRoom(GameObject roomToGenerate, bool isDeadEnd = false) { Quaternion rotation = Quaternion.LookRotation(this.transform.forward); Vector3 position = GenerateRelativeVector(rotation.eulerAngles.y, bias); GameObject generatedRoom = Instantiate(roomToGenerate, position, rotation); yield return(null); ConnectionPoint[] connectionPoints = null; ConnectionPoint chosenPoint = null; if (!isDeadEnd) { connectionPoints = generatedRoom.GetComponentsInChildren <ConnectionPoint>(); chosenPoint = connectionPoints[0]; } CheckCollision validatorNewRoom = generatedRoom.GetComponentInChildren <CheckCollision>(); validatorNewRoom.TurnOnCollider(); yield return(new WaitForSeconds(0.03f)); if (validatorNewRoom.GetIsCollided()) { Destroy(generatedRoom); yield return(null); } else { this.SetConnected(); if (!isDeadEnd) { //deactivate Deco before generating NavMesh generatedRoom.transform.Find("Environment").Find("Deco").gameObject.SetActive(false); MapGenerator.AddGeneratedRoom(generatedRoom); chosenPoint.SetConnected(); MapGenerator.AddConnectionPoints(connectionPoints); } } }
public IEnumerator GenerateDeadend() { GameObject roomToGenerate = deadend; Quaternion rotation = Quaternion.LookRotation(this.transform.forward); Vector3 position = GenerateRelativeVector(rotation.eulerAngles.y, bias); GameObject generatedRoom = Instantiate(roomToGenerate, position, rotation); yield return(null); CheckCollision validatorNewRoom = generatedRoom.GetComponentInChildren <CheckCollision>(); validatorNewRoom.TurnOnCollider(); yield return(new WaitForSeconds(0.05f)); if (validatorNewRoom.GetIsCollided()) { Destroy(generatedRoom); yield return(null); } else { this.SetConnected(); } }