public GameObject CreateRoom(LevelController _parent, int _roomId, string room) { parent = _parent; roomId = _roomId; GameObject floorObj = Instantiate(FloorPrefab); floorObj.transform.SetParent(transform, false); floorObj.name = "Floor"; int pos = 0; for (int i = 0; i < room.Length; i++) { int x = (pos % ROOM_SIZE); int y = (pos / ROOM_SIZE); char c = room[i]; char c2; switch (c) { case 'W': // WALL InstantiateOn(x, y, WallPrefab); pos++; break; case '_': // EMPTY pos++; break; case 'S': // START i++; c2 = room[i]; switch (c2) { case 'R': InstantiateOn(x, y, StartRedPrefab); parent.SetPlayer1Spawn(roomId, x, y); break; case 'B': InstantiateOn(x, y, StartBluePrefab); parent.SetPlayer2Spawn(roomId, x, y); break; default: Debug.LogError("Expecting R/B: " + Pos2Str(pos)); break; } pos++; break; case 'E': // END i++; c2 = room[i]; { GameObject endObj = null; switch (c2) { case 'R': endObj = InstantiateOn(x, y, EndRedPrefab); break; case 'B': endObj = InstantiateOn(x, y, EndBluePrefab); break; default: Debug.LogError("Expecting R/B: " + Pos2Str(pos)); break; } EndItem end = endObj.GetComponent <EndItem>(); end.controller = parent; } pos++; break; case 'L': // LEVER InstantiateOn(x, y, LeverPrefab); pos++; break; case 'P': // PIPE InstantiateOn(x, y, PipePrefab); pos++; break; case 'B': // BUTTON i++; c2 = room[i]; { GameObject butGo = InstantiateOn(x, y, ButtonPrefab); ButtonItem butItem = butGo.GetComponent <ButtonItem>(); int group = Integer_Char2Int(c2, pos); butItem.baseColor = paletteId[group]; butItem.group = group; butItem.controller = parent; } pos++; break; case 'H': // DOOR i++; c2 = room[i]; { GameObject doorGo = InstantiateOnWithRotation(x, y, 0, DoorButtonPrefab); ButtonDoorItem doorItem = doorGo.GetComponent <ButtonDoorItem>(); int group = Integer_Char2Int(c2, pos); doorItem.SetColor(paletteId[group]); doorItem.group = group; parent.AddButtonDoor(doorItem); } pos++; break; case 'V': // DOOR i++; c2 = room[i]; { GameObject doorGo = InstantiateOnWithRotation(x, y, 1, DoorButtonPrefab); ButtonDoorItem doorItem = doorGo.GetComponent <ButtonDoorItem>(); int group = Integer_Char2Int(c2, pos); doorItem.SetColor(paletteId[group]); doorItem.group = group; parent.AddButtonDoor(doorItem); } pos++; break; case 'D': // DOOR i++; c2 = room[i]; { int rot = Rotation_Char2Int(c2, pos); InstantiateOnWithRotation(x, y, rot, DoorPrefab); } pos++; break; case 'J': // DOORKEY i++; c2 = room[i]; { int rot = Rotation_Char2Int(c2, pos); GameObject g = InstantiateOnWithRotation(x, y, rot, DoorPrefab); g.GetComponent <BasicDoorItem>().SetKey(); } pos++; break; case 'K': // KEY InstantiateOn(x, y, KeyPrefab); pos++; break; default: // ignore break; } } return(floorObj); }
public void AddButtonDoor(ButtonDoorItem door) { buttonDoors.Add(door); }