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; }); } }
public async Task UpdateRoomList() { await this.client.ConnectToContract(); BlackjackContractClient.GetRoomsOutput getRoomsOutput = await this.client.Room.GetRooms(); this.rooms.Clear(); for (int i = 0; i < getRoomsOutput.RoomNames.Count; i++) { byte[] roomNameBytes = getRoomsOutput.RoomNames[i]; string roomName = Encoding.UTF8.GetString(roomNameBytes); this.rooms.Add(new Room { Id = getRoomsOutput.RoomIds[i], Creator = (Address)getRoomsOutput.Creators[i], Name = roomName }); } this.RoomListChanged?.Invoke(); }