/* * Add windows to the outside walls */ public void AddWindows() { int wallIndex = 0; int windowIndex = Random.Range(0, _windowPrefabs.Length); GameObject windowPrefab = _windowPrefabs[windowIndex]; Bounds bounds = windowPrefab.GetComponent <MeshRenderer>().bounds; float windowWidth = bounds.max.x - bounds.min.x; Debug.Log("Window Size: " + windowWidth); LineRange groundRangeX = _ground.GetXRange(); LineRange groundRangeZ = _ground.GetZRange(); foreach (bool isOutsideWall in _wall.GetIsOutsideWalls()) { if (isOutsideWall && Random.Range(0f, 1f) < _windowChance[wallIndex]) { // Add Window(s) List <LineRange> freeWallSections = _wall.GetEmptySections(wallIndex); foreach (LineRange freeWallSection in freeWallSections) { if (freeWallSection.max - freeWallSection.min > windowWidth) { // Window fits Vector3 windowAt = _wall.AddToWall(wallIndex, freeWallSection, windowWidth, (_ceiling.GetHeight() / 3) * 2); GameObject window = Instantiate <GameObject>(windowPrefab); window.transform.Rotate(_wall.GetWallRotate(wallIndex) * Vector3.up); window.transform.position = windowAt; Debug.Log("Window " + wallIndex + "(" + windowAt.x + "," + windowAt.z + "): " + window.transform.position); window.transform.parent = transform; window.transform.name = "Window" + wallIndex + windowPrefab.name; window.tag = "Decoration"; AddWindowLight(wallIndex, window); _windowCount++; // Only one window per wall break; } } } wallIndex++; } }
// Create the Doors to get in and out public void AddDoors() { int doorIndex = Random.Range(0, _doorPrefabs.Length); GameObject doorPrefab = _doorPrefabs[doorIndex]; Bounds bounds = doorPrefab.GetComponent <MeshRenderer>().bounds; float doorWidth = (bounds.max.x - bounds.min.x) * _doorScale.x; float doorHeight = 1.05f; // (bounds.max.y - bounds.min.y) *_doorScale.y; int wallIndex = 0; foreach (bool isOutsideWall in _wall.GetIsOutsideWalls()) { if (!isOutsideWall) { // Add a Door if we want Debug.Log("Try Door on wall " + wallIndex); // Find location player can get to door handle on wall List <LineRange> accessibleWall = _wall.GetAccessibleSections(wallIndex); Debug.Log(accessibleWall.Count); // No need to check if the wall is free (it should be as we add doors first) // Find a section big enough for a door foreach (LineRange wallSection in accessibleWall) { Debug.Log(wallSection); if (wallSection.Range() > doorWidth) { Debug.Log("Door on wall " + wallIndex); Vector3 doorAt = _wall.AddToWall(wallIndex, wallSection, doorWidth, doorHeight); GameObject door = Instantiate <GameObject>(doorPrefab); door.transform.Rotate(_wall.GetWallRotate(wallIndex) * Vector3.forward); door.transform.position = doorAt; door.transform.localScale = _doorScale; Debug.Log("door " + wallIndex + "(" + doorAt.x + "," + doorAt.z + "): " + door.transform.position); door.transform.parent = transform; door.transform.name = "Door" + wallIndex + doorPrefab.name; door.tag = "Door"; } } } wallIndex++; } }