_xiaofang/xiaofang/Assets/Res/gsj/scripts/ReadRoom.cs
2024-12-26 22:26:18 +08:00

82 lines
2.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)
{
if (room.Status == "进行中")
{
bool found = false; // 标记是否找到匹配的用户 ID
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;
found = true; // 找到匹配用户 ID
break; // 直接跳出循环
}
}
// 如果没有找到匹配的用户 ID跳转到 "yhj" 场景
if (!found)
{
Debug.Log("未找到匹配用户 ID跳转到场景 'yhj'");
SceneManager.LoadScene("yhj");
}
}
else
{
Debug.Log("状态不是 '进行中',跳转到场景 'yhj'");
SceneManager.LoadScene("yhj");
}
}
}
else
{
Debug.LogError("获取房间列表失败!");
}
}
// Update is called once per frame
void Update()
{
}
}