From e92750730f05beb532bd00751589fedc7eb46ebb Mon Sep 17 00:00:00 2001 From: liuliang <597380732@qq.com> Date: Wed, 25 Dec 2024 22:10:20 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=B8=BB=E6=8C=81=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xiaofang/Assets/Res/gsj/scripts/Panel3.cs | 1 - xiaofang/Assets/Res/gsj/scripts/ReadRoom.cs | 64 ++++++++++++ .../Assets/Res/gsj/scripts/ReadRoom.cs.meta | 11 +++ .../Assets/Res/gsj/scripts/RoomManager.cs | 24 +++++ xiaofang/Assets/Res/gsj/scripts/Starthost.cs | 4 + .../Assets/Resources/gsjUI/GameObject.prefab | 2 +- xiaofang/Assets/Scenes/Tmap 3.unity | 98 ++++++++++--------- xiaofang/Assets/Scenes/loginscene.unity | 84 ++++++++++++++++ xiaofang/Assets/Scenes/yhj.unity | 26 ++--- xiaofang/Assets/Script/login/MyGlobal.cs | 13 ++- .../Assets/Script/loginScripts/LoginPanel.cs | 11 ++- 11 files changed, 268 insertions(+), 70 deletions(-) create mode 100644 xiaofang/Assets/Res/gsj/scripts/ReadRoom.cs create mode 100644 xiaofang/Assets/Res/gsj/scripts/ReadRoom.cs.meta 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 Date: Wed, 25 Dec 2024 22:49:02 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=94=B9=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Assets/Script/loginScripts/LoginPanel.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/xiaofang/Assets/Script/loginScripts/LoginPanel.cs b/xiaofang/Assets/Script/loginScripts/LoginPanel.cs index e6a1f523..74e47e24 100644 --- a/xiaofang/Assets/Script/loginScripts/LoginPanel.cs +++ b/xiaofang/Assets/Script/loginScripts/LoginPanel.cs @@ -63,16 +63,25 @@ public class LoginPanel : Base // 打印 access_token Debug.Log(serverData.data.access_token); - // 跳转场景 - ReadRoom.instance.head(); + //如果是管理员账号就跳预定演练 //if (loginBody.userType == "company_user") - // SceneManager.LoadScene(1); + if(loginBody.username == id.text && loginBody.password == pwd.text) + { + SceneManager.LoadScene(1); + } + if(id.text == "13051628292" && pwd.text == "ZF16c788632") + { + ReadRoom.instance.head(); + } + ////如果是玩家账号就跳转到加入房间界面 //if (loginBody.userType == "Player") - // SceneManager.LoadScene(2); + // SceneManager.LoadScene(5); + // 跳转场景 + //ReadRoom.instance.head(); }