void InstantiateRooms(HouseStructure h) { for (int i = 0; i < h.size; i++) { for (int j = 0; j < h.size; j++) { Vector2 pos = new Vector2(j - (int)(h.size / 2), (int)(h.size / 2) - i) * new Vector2(RoomWidth, RoomWidth - 1); RoomStructure rs = h.roomStructures[i * h.size + j]; GameObject room = Instantiate(roomPrefab, pos, Quaternion.identity); RoomTileController rtc = room.GetComponent <RoomTileController>(); rtc.TilePalette = TilePalettes[Random.Range(0, TilePalettes.Length)]; rtc.TilePaletteName = rtc.TilePalette.name; rtc.Structure = rs; rtc.RoomStructureName = rs.name; rtc.LayoutIndex = Random.Range(0, rtc.Layouts.Length); NetworkServer.Spawn(room); } } }
// Start is called before the first frame update void Start() { TilePalette = Resources.Load <RoomTilePalette>("RoomTilePalettes/" + TilePaletteName); Structure = Resources.Load <RoomStructure>("RoomStructures/" + RoomStructureName); DrawTiles(); if (transform.position == Vector3.zero) { Objects = Instantiate(LayoutCenter, transform.position, Quaternion.identity).GetComponentInChildren <Tilemap>(); } else { Objects = Instantiate(Layouts[LayoutIndex], transform.position, Quaternion.identity).GetComponentInChildren <Tilemap>(); } if (isServer) { InstantiateMatches(); } }
public static void MakeRoom(Map map, CellRect rect, RoomStructure rs) { if (rs.wallMaterial == null) { Faction faction = Find.FactionManager.RandomNonHostileFaction(false, false, true, TechLevel.Spacer); rs.wallMaterial = BaseGenUtility.RandomCheapWallStuff(faction, false); } if (rs.floorMaterial == null) { rs.floorMaterial = BaseGenUtility.CorrespondingTerrainDef(rs.wallMaterial, true); } if (rs.floorMaterial == null) { rs.floorMaterial = BaseGenUtility.RandomBasicFloorDef(Faction.OfMechanoids, false); } MapGenUtility.TileArea(map, rect, rs.floorMaterial, rs.floorChance); MapGenUtility.MakeLongWall(new IntVec3(rect.minX, 1, rect.minZ), map, rect.Width, true, rs.wallS, rs.wallMaterial); MapGenUtility.MakeLongWall(new IntVec3(rect.minX, 1, rect.maxZ), map, rect.Width, true, rs.wallN, rs.wallMaterial); MapGenUtility.MakeLongWall(new IntVec3(rect.minX, 1, rect.minZ), map, rect.Height, false, rs.wallW, rs.wallMaterial); MapGenUtility.MakeLongWall(new IntVec3(rect.maxX, 1, rect.minZ), map, rect.Height, false, rs.wallE, rs.wallMaterial); for (int i = 0; i < rs.doorN; i++) { MapGenUtility.RandomAddDoor(new IntVec3(rect.minX + 2, 1, rect.maxZ), map, rect.Width - 3, true, rs.wallMaterial); } for (int j = 0; j < rs.doorS; j++) { MapGenUtility.RandomAddDoor(new IntVec3(rect.minX + 2, 1, rect.minZ), map, rect.Width - 3, true, rs.wallMaterial); } for (int k = 0; k < rs.doorE; k++) { MapGenUtility.RandomAddDoor(new IntVec3(rect.minX, 1, rect.minZ + 2), map, rect.Height - 3, false, rs.wallMaterial); } for (int l = 0; l < rs.doorW; l++) { MapGenUtility.RandomAddDoor(new IntVec3(rect.maxX, 1, rect.minZ + 2), map, rect.Height - 3, false, rs.wallMaterial); } map.MapUpdate(); }