private void SetBackGround(Space _Space) { if (_Space == null) { return; } if (_Space.CheckLeaf()) { SetBackGround(_Space.left); SetBackGround(_Space.right); } else { var roomType = _Space.roomType; for (int i = (int)_Space.rect.x; i < _Space.rect.xMax; i++) { for (int j = (int)_Space.rect.y; j < _Space.rect.yMax; j++) { if (map[i, j] == null) { map[i, j] = new MapTileData(roomType, (int)TileType.BackGround, UnityEngine.Random.Range(0, tileRefernce[roomType].backGroundSprite.Count)); } } } } }
/// <summary> /// 공간분할 /// </summary> /// <param name="_Space"></param> public void CreateBSP(Space _Space) { Debug.Log("Splitting Space : " + _Space.spaceID + " : " + _Space.rect); if (!_Space.CheckLeaf()) { //rect높이, 가로 길이가 maxroomsize보다 클경우, if (_Space.rect.width > maxRoomSize || _Space.rect.height > maxRoomSize) { //Split 실행 split실행후 다시 bsp체크 if (_Space.Split(minRoomSize)) { Debug.Log("Splitted Space : " + _Space.spaceID + " in " + _Space.left.spaceID + ": " + _Space.left.rect + ", " + _Space.right.spaceID + ": " + _Space.right.rect); //재귀 CreateBSP(_Space.left); CreateBSP(_Space.right); } } } }
/// <summary> /// 방으로 설정한 부분을 배열 map에서 타일 설정 /// </summary> /// <param name="_Space"></param> public void SetRoom(Space _Space) { if (_Space == null) { return; } if (_Space.CheckLeaf()) { SetRoom(_Space.left); SetRoom(_Space.right); } else { var roomType = _Space.roomType; for (int i = (int)_Space.room.x; i < _Space.room.xMax; i++) { for (int j = (int)_Space.room.y; j < _Space.room.yMax; j++) { map[i, j] = new MapTileData(roomType, (int)TileType.Floor, UnityEngine.Random.Range(0, tileRefernce[roomType].floorSprite.Count)); } } } }
/// <summary> /// 방 노드를 모두 돌면서 테두리 생성 /// </summary> /// <param name="_Space"></param> private void SetRoomOutLine(Space _Space) { if (_Space == null) { return; } if (_Space.CheckLeaf()) { SetRoomOutLine(_Space.left); SetRoomOutLine(_Space.right); } else { var x = (int)_Space.room.x; var y = (int)_Space.room.y; var xMax = (int)_Space.room.xMax; var yMax = (int)_Space.room.yMax; var wallTileNum = (int)TileType.Wall; var roomType = _Space.roomType; for (int i = x - 1; i <= xMax; i++) { for (int j = y - 1; j <= yMax; j++) { if (map[i, j] == null) { if (i == x - 1 && j == y - 1) { map[i, j] = new MapTileData(roomType, wallTileNum, (int)Dir.LeftBottom); } else if (i == x - 1 && j == yMax) { map[i, j] = new MapTileData(roomType, wallTileNum, (int)Dir.LeftTop); } else if (i == xMax && j == y - 1) { map[i, j] = new MapTileData(roomType, wallTileNum, (int)Dir.RightBottom); } else if (i == xMax && j == yMax) { map[i, j] = new MapTileData(roomType, wallTileNum, (int)Dir.RightTop); } else if (i == x - 1) { map[i, j] = new MapTileData(roomType, wallTileNum, (int)Dir.Left); } else if (j == y - 1) { map[i, j] = new MapTileData(roomType, wallTileNum, (int)Dir.Bottom); } else if (i == xMax) { map[i, j] = new MapTileData(roomType, wallTileNum, (int)Dir.Right); } else if (j == yMax) { map[i, j] = new MapTileData(roomType, wallTileNum, (int)Dir.Top); } } } } } }