_xiaofang/xiaofang/Assets/Res/gsj/scripts/ReadRoom.cs
2024-12-26 03:46:07 +08:00

67 lines
2.0 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class ReadRoom : MonoBehaviour
{
public static ReadRoom instance;
public gameRoomList gameRoomListInstance; // 引用 gameRoomList 脚本实例
public GameRoomListResponse gameRoomListResponse;
private List<GameRoomListData> roomDataList;
public JSONReader js;
public bool isenter=false;//主持人进入
// Start is called before the first frame update
void Start()
{
instance = this;
gameRoomListInstance = FindObjectOfType<gameRoomList>();
}
//主持人直接进入房间要获取的数据
public async void head()
{
var response = await gameRoomListInstance.getGameRoomList();
if (response != null && response.Data != null)
{
roomDataList = response.Data;
Debug.Log($"获取到的房间数量:{roomDataList.Count}");
// 获取当前日期
DateTime currentDate = DateTime.Now;
//将当前日期格式化为 "yyyy/MM/dd" 形式
string formattedDate = currentDate.ToString("yyyy/MM/dd");
// 调用方法,动态生成房间元素
foreach (var room in roomDataList)
{
for (int i = 0; i < room.PlayerList.Count; i++)
{
if ((GlobalData.ServerData.data.userId == room.PlayerList[i].UserId) && ("2024/12/20" == room.ReserveDate))
{
Debug.Log("可以直接进入房间");
SceneManager.LoadScene("Tmap 1");
isenter = true;
}
//else
//{
// Debug.Log("不可以直接进入房间");
// SceneManager.LoadScene(1);
//}
}
}
}
else
{
Debug.LogError("获取房间列表失败!");
}
}
// Update is called once per frame
void Update()
{
}
}