using System.Collections; using System.Collections.Generic; //using System.Drawing; using UnityEngine; using UnityEngine.UI; public class RoomManager : MonoBehaviour { public gameRoomList gameRoomListInstance; // 引用 gameRoomList 脚本实例 public GameRoomListResponse gameRoomListResponse; private List roomDataList; private Transform contentParent; // Scroll View 的 Content 物体 public GameObject roomPrefab;//房间的预制体 public JSONReader js; void Start() { gameRoomListInstance = FindObjectOfType(); contentParent =transform.Find("Mid/Scroll View/Viewport/Content").transform; gameRoomListInstance = FindObjectOfType(); FetchRoomList(); } // 异步获取房间数据 private async void FetchRoomList() { var response = await gameRoomListInstance.getGameRoomList(); if (response != null && response.Data != null) { roomDataList = response.Data; Debug.Log($"获取到的房间数量:{roomDataList.Count}"); // 调用方法,动态生成房间元素 PopulateRoomList(roomDataList); } else { Debug.LogError("获取房间列表失败!"); } } // 动态生成房间预制体,并赋值数据 private void PopulateRoomList(List roomDataList) { foreach (var room in roomDataList) { // 实例化房间预制体 GameObject roomItem = Instantiate(roomPrefab, contentParent); // 查找房间预制体中的 UI 组件并赋值 Text roomNameText = roomItem.transform.Find("down/detail").GetComponent(); Text roomStatusText = roomItem.transform.Find("up/type").GetComponent(); Button roomButton = roomItem.transform.GetComponent