88 lines
3.4 KiB
C#
88 lines
3.4 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
//using System.Drawing;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
public class RoomManager : MonoBehaviour
|
|||
|
{
|
|||
|
public gameRoomList gameRoomListInstance; // <20><><EFBFBD><EFBFBD> gameRoomList <20>ű<EFBFBD>ʵ<EFBFBD><CAB5>
|
|||
|
public GameRoomListResponse gameRoomListResponse;
|
|||
|
private List<GameRoomListData> roomDataList;
|
|||
|
private Transform contentParent; // Scroll View <20><> Content <20><><EFBFBD><EFBFBD>
|
|||
|
public GameObject roomPrefab;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD>
|
|||
|
public JSONReader js;
|
|||
|
void Start()
|
|||
|
{
|
|||
|
gameRoomListInstance = FindObjectOfType<gameRoomList>();
|
|||
|
contentParent =transform.Find("Mid/Scroll View/Viewport/Content").transform;
|
|||
|
gameRoomListInstance = FindObjectOfType<gameRoomList>();
|
|||
|
FetchRoomList();
|
|||
|
}
|
|||
|
// <20>첽<EFBFBD><ECB2BD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
private async void FetchRoomList()
|
|||
|
{
|
|||
|
var response = await gameRoomListInstance.getGameRoomList();
|
|||
|
|
|||
|
if (response != null && response.Data != null)
|
|||
|
{
|
|||
|
roomDataList = response.Data;
|
|||
|
Debug.Log($"<22><>ȡ<EFBFBD><C8A1><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>{roomDataList.Count}");
|
|||
|
|
|||
|
// <20><><EFBFBD>÷<EFBFBD><C3B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̬<EFBFBD><CCAC><EFBFBD>ɷ<EFBFBD><C9B7><EFBFBD>Ԫ<EFBFBD><D4AA>
|
|||
|
PopulateRoomList(roomDataList);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Debug.LogError("<22><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// <20><>̬<EFBFBD><CCAC><EFBFBD>ɷ<EFBFBD><C9B7><EFBFBD>Ԥ<EFBFBD><D4A4><EFBFBD>壬<EFBFBD><E5A3AC><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>
|
|||
|
private void PopulateRoomList(List<GameRoomListData> roomDataList)
|
|||
|
{
|
|||
|
foreach (var room in roomDataList)
|
|||
|
{
|
|||
|
// ʵ<><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD>
|
|||
|
GameObject roomItem = Instantiate(roomPrefab, contentParent);
|
|||
|
|
|||
|
// <20><><EFBFBD>ҷ<EFBFBD><D2B7><EFBFBD>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD> UI <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|||
|
Text roomNameText = roomItem.transform.Find("down/detail").GetComponent<Text>();
|
|||
|
Text roomStatusText = roomItem.transform.Find("up/type").GetComponent<Text>();
|
|||
|
Button roomButton = roomItem.transform.GetComponent<Button>();
|
|||
|
|
|||
|
if (roomNameText != null) roomNameText.text = ""+js.SetUIText(int.Parse(room.SceneId))+" "+ js.SetUIText(int.Parse(room.SubjectId));
|
|||
|
if (roomStatusText != null)
|
|||
|
{
|
|||
|
// <20><><EFBFBD><EFBFBD> room.Status <20><>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>״̬<D7B4>ı<EFBFBD>
|
|||
|
switch (room.Status)
|
|||
|
{
|
|||
|
case "0":
|
|||
|
roomStatusText.text = "<22><>Ԥ<EFBFBD><D4A4>";
|
|||
|
roomStatusText.color = new Color(255f / 255f, 255f / 255f, 0f / 255f);
|
|||
|
break;
|
|||
|
case "1":
|
|||
|
roomStatusText.text = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|||
|
break;
|
|||
|
case "2":
|
|||
|
roomStatusText.text = "<22>ѽ<EFBFBD><D1BD><EFBFBD>";
|
|||
|
roomStatusText.color = new Color(103f / 255f, 103f / 255f, 103f / 255f);
|
|||
|
break;
|
|||
|
default:
|
|||
|
roomStatusText.text = "δ֪״̬";
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
// <20><><EFBFBD><EFBFBD> RoomDataHolder <20>ű<EFBFBD><C5B1><EFBFBD><EFBFBD>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD>
|
|||
|
Status dataHolder = roomItem.GetComponent<Status>();
|
|||
|
dataHolder.SetRoomData(room.RoomId, room.SceneId, room.SubjectId, room.TemplateId, room.Status);
|
|||
|
// Ϊ<><CEAA>ť<EFBFBD><C5A5><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뷿<EFBFBD><EBB7BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
roomButton.onClick.AddListener(() => OnRoomButtonClicked(room));
|
|||
|
}
|
|||
|
}
|
|||
|
// <20><><EFBFBD>䰴ť<E4B0B4><C5A5><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
|||
|
private void OnRoomButtonClicked(GameRoomListData room)
|
|||
|
{
|
|||
|
Debug.Log($"<22><><EFBFBD><EFBFBD><EFBFBD>˷<EFBFBD><CBB7><EFBFBD>: {room.RoomId}, ״̬: {room.Status}," +
|
|||
|
$"ģ<><C4A3>ID: {room.TemplateId},<2C><><EFBFBD><EFBFBD>ID: {room.SceneId},<2C><>ĿID: {room.SubjectId}");
|
|||
|
}
|
|||
|
}
|