using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Analytics; using UnityEngine.SceneManagement; using UnityEngine.UI; public class ReadRoom : MonoBehaviour { public static ReadRoom instance; public gameRoomList gameRoomListInstance; // 引用 gameRoomList 脚本实例 public GameRoomListResponse gameRoomListResponse; private List roomDataList; public JSONReader js; public bool isenter=false;//主持人进入 public bool isadministrator = false;//是否是管理员 private bool isStartRoom = false;//主持人是否已经点击演练开始 public bool iszongzhihui = false; public int RoleId; public loginData playerdetail; // Start is called before the first frame update void Start() { instance = this; gameRoomListInstance = FindObjectOfType(); } void OnEnable() { // 订阅事件 Starthost.OnBoolStart += HandleRoomControl; } void OnDisable() { // 取消订阅事件 Starthost.OnBoolStart -= HandleRoomControl; } //主持人直接进入房间要获取的数据 public async void head() { var response = await gameRoomListInstance.getGameRoomList(); if (response != null && response.Data != null) { Debug.LogError(GlobalData.ServerData.data.isCreater); if(GlobalData.ServerData.data.isCreater == "N") { Debug.LogError(1); SceneManager.LoadScene("yhj"); isadministrator=false; }else { isadministrator = true; ; } foreach(var item in response.Data) { foreach(var item1 in item.PlayerList) { if(GlobalData.ServerData.data.userId==item1.UserId) { playerdetail = GlobalData.ServerData.data; RoleId = item1.RoleId; if(item1.RoleId==8000)//主持人 { isenter=true; } else if(item1.RoleId == 8001)//总指挥 { iszongzhihui=true; } else { isenter = false; } } } } 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 == "1"||room.Status=="0") { bool found = false; // 标记是否找到匹配的用户 ID if (!isStartRoom) { for (int i = 0; i < room.PlayerList.Count; i++) { if ((GlobalData.ServerData.data.userId == room.PlayerList[i].UserId) && (formattedDate == room.ReserveDate)) { //传人物职业ID //Player.CSZS.SetPlayerID(room.PlayerList[i].RoleId); Debug.Log("可以直接进入房间"); SceneManager.LoadScene("Tmap 1"); //if(GlobalData.ServerData.data.openId==) isenter = true; found = true; // 找到匹配用户 ID break; // 直接跳出循环 } } } else { Debug.Log("主持人点击了开始演练,但没有进入场景,要进入大厅房间"); //SceneManager.LoadScene("yhj"); break; } // 如果没有找到匹配的用户 ID,跳转到 "yhj" 场景 if (!found) { Debug.Log("未找到匹配用户 ID,跳转到场景 'yhj'"); //SceneManager.LoadScene("yhj"); break; } // 如果找到了匹配房间,不需要再检查其他房间 if (found) break; } else { Debug.Log("状态不是 '进行中',跳转到场景 'yhj'"); //SceneManager.LoadScene("yhj"); break; } } } else { Debug.LogError("获取房间列表失败!"); } } // Update is called once per frame void Update() { } void HandleRoomControl(bool isStart) { isStartRoom = isStart; } }