diff --git a/xiaofang/Assets/Res/gsj/scripts/Panel3.cs b/xiaofang/Assets/Res/gsj/scripts/Panel3.cs index 17134d0a..919402c7 100644 --- a/xiaofang/Assets/Res/gsj/scripts/Panel3.cs +++ b/xiaofang/Assets/Res/gsj/scripts/Panel3.cs @@ -2,7 +2,6 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; -using static UnityEditor.Experimental.GraphView.GraphView; public class Panel3 : MonoBehaviour { diff --git a/xiaofang/Assets/Res/gsj/scripts/ReadRoom.cs b/xiaofang/Assets/Res/gsj/scripts/ReadRoom.cs new file mode 100644 index 00000000..e8f87959 --- /dev/null +++ b/xiaofang/Assets/Res/gsj/scripts/ReadRoom.cs @@ -0,0 +1,64 @@ +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 roomDataList; + public JSONReader js; + // Start is called before the first frame update + void Start() + { + instance = this; + gameRoomListInstance = FindObjectOfType(); + } + //主持人直接进入房间要获取的数据 + 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(2); + } + //else + //{ + // Debug.Log("不可以直接进入房间"); + // SceneManager.LoadScene(1); + //} + } + } + + + } + else + { + Debug.LogError("获取房间列表失败!"); + } + } + // Update is called once per frame + void Update() + { + + } +} diff --git a/xiaofang/Assets/Res/gsj/scripts/ReadRoom.cs.meta b/xiaofang/Assets/Res/gsj/scripts/ReadRoom.cs.meta new file mode 100644 index 00000000..9e95332d --- /dev/null +++ b/xiaofang/Assets/Res/gsj/scripts/ReadRoom.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 67494b9dd890ac44fbcec6f6b28c3d60 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/xiaofang/Assets/Res/gsj/scripts/RoomManager.cs b/xiaofang/Assets/Res/gsj/scripts/RoomManager.cs index 093f13ac..a85a612a 100644 --- a/xiaofang/Assets/Res/gsj/scripts/RoomManager.cs +++ b/xiaofang/Assets/Res/gsj/scripts/RoomManager.cs @@ -1,7 +1,9 @@ +using System; using System.Collections; using System.Collections.Generic; //using System.Drawing; using UnityEngine; +using UnityEngine.SceneManagement; using UnityEngine.UI; public class RoomManager : MonoBehaviour { @@ -18,6 +20,7 @@ public class RoomManager : MonoBehaviour gameRoomListInstance = FindObjectOfType(); FetchRoomList(); } + // 异步获取房间数据 private async void FetchRoomList() { @@ -40,6 +43,7 @@ public class RoomManager : MonoBehaviour // 动态生成房间预制体,并赋值数据 private void PopulateRoomList(List roomDataList) { + foreach (var room in roomDataList) { // 实例化房间预制体 @@ -75,6 +79,21 @@ public class RoomManager : MonoBehaviour // 添加 RoomDataHolder 脚本并存储数据 Status dataHolder = roomItem.GetComponent(); dataHolder.SetRoomData(room.RoomId, room.SceneId, room.SubjectId, room.TemplateId, room.Status); + // 获取当前日期 + DateTime currentDate = DateTime.Now; + + //将当前日期格式化为 "yyyy/MM/dd" 形式 + string formattedDate = currentDate.ToString("yyyy/MM/dd"); + for (int i = 0; i < room.PlayerList.Count; i++) + { + if (GlobalData.ServerData.data.userId== room.PlayerList[i].UserId) + { + Debug.Log("可以直接进入房间"); + //SceneManager.LoadScene(2); + + } + Debug.Log("UserId=" + room.PlayerList[i].UserId); + } // 为按钮添加点击事件,并传入房间数据 roomButton.onClick.AddListener(() => OnRoomButtonClicked(room)); } @@ -84,5 +103,10 @@ public class RoomManager : MonoBehaviour { Debug.Log($"点击了房间: {room.RoomId}, 状态: {room.Status}," + $"模板ID: {room.TemplateId},场景ID: {room.SceneId},科目ID: {room.SubjectId}"); + Debug.Log("ReserveDate=" + room.ReserveDate); + for(int i=0;i