private async Task RefreshRoomList() { await this.client.ConnectToContract(); BlackjackContractClient.GetRoomsOutput getRoomsOutput = await this.client.Room.GetRooms(); foreach (Transform child in this.RoomList.transform) { Destroy(child.gameObject); } for (int i = 0; i < getRoomsOutput.RoomNames.Count; i++) { byte[] roomNameBytes = getRoomsOutput.RoomNames[i]; string roomName = Encoding.UTF8.GetString(roomNameBytes); GameObject roomListItemGo = Instantiate(this.PrefabsContainer.RoomListItemPrefab, this.RoomList.transform); RoomListItemUIContainer roomListItemUiContainer = roomListItemGo.GetComponent <RoomListItemUIContainer>(); roomListItemUiContainer.ButtonText.text = roomName; int index = i; roomListItemUiContainer.Button.onClick.AddListener(async() => { BigInteger roomId = getRoomsOutput.RoomIds[index]; await this.client.Room.JoinRoom(roomId); this.currentRoomId = roomId; }); } }
private void UpdateRoomList() { foreach (Transform child in this.RoomList.transform) { Destroy(child.gameObject); } foreach (Room room in this.GameStateController.Rooms) { GameObject roomListItemGo = Instantiate(this.PrefabsContainer.RoomListItemPrefab, this.RoomList.transform); RoomListItemUIContainer roomListItemUiContainer = roomListItemGo.GetComponent <RoomListItemUIContainer>(); roomListItemUiContainer.ButtonText.text = room.Name; roomListItemUiContainer.Button.onClick.AddListener(() => JoinRoomClickHandler(room.Id)); } this.RoomListNoRoomsLabel.SetActive(this.GameStateController.Rooms.Count == 0); }