_xiaofang/xiaofang/Assets/Res/gsj/scripts/Status.cs
2024-12-20 10:10:19 +08:00

197 lines
5.8 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Threading.Tasks;
using UnityEngine.SceneManagement;
public class Status : MonoBehaviour
{
private Button button;
private Text type;//房间状态文本
private GameObject three;//自己参与时出现的文字图像
private GameObject down;
public bool isParticipate;//是否参与
public bool isEnd=false;//是否结束
public bool isOngoing = false;//是否在进行
public bool isScheduled=false;//是否预定
private Image pop;
private Image arrow;
private float time = 3f;
private float await = 0;
private Button Assessmentreport;//评估报告按钮
private Button Review;//复盘按钮;
private Button repair;//修复按钮
private Button cancelbooking;//取消预定按钮
private bool eventAdded = false; // 防止重复添加事件
public bool isadministrator;//是否为管理员
public Drill drill;
private string scenename;//场景名
private string accidenttype;//事故类型
private Text text;//场景名加事故类型的文本
private Text timetext;//房间时间文本
private gameRoomList gameRoomListInstance; // 引用 gameRoomList 脚本实例
private List<GameRoomListData> roomDataList; // 保存获取到的房间列表
public string RoomId;
public string status;
public string TemplateId;
public string SceneId;
public string SubjectId;
// Start is called before the first frame update
void Start()
{
button=GetComponent<Button>();
button.onClick.AddListener(OnClickBtn);
type=transform.Find("up/type").GetComponent<Text>();
down = transform.Find("down").gameObject;
Assessmentreport = transform.Find("down/end/repair ").GetComponent<Button>();
Assessmentreport.gameObject.SetActive(false);
Review = transform.Find("down/end/Cancel").GetComponent<Button>();
Review.gameObject.SetActive(false);
repair = transform.Find("down/Reserve/repair ").GetComponent<Button>();
repair.gameObject.SetActive(false);
cancelbooking = transform.Find("down/Reserve/Cancel").GetComponent<Button>();
cancelbooking.gameObject.SetActive(false);
three = transform.Find("down/Schedule").gameObject;
three.SetActive(false);
pop=transform.Find("down/Schedule/pop").GetComponent<Image>();
arrow=transform.Find("down/Schedule/arrowhead ").GetComponent<Image>();
drill=GameObject.Find("Panel").GetComponent<Drill>();
drill.OnBoolAChanged += OnBoolAChanged;
text=transform.Find("down/detail").GetComponent<Text>();
timetext=transform.Find("up/date").GetComponent <Text>();
// 查找场景中的 gameRoomList 脚本实例
gameRoomListInstance = FindObjectOfType<gameRoomList>();
}
public void SetRoomData(string roomId, string sceneId, string subjectId, string templateId, string statu)
{
RoomId = roomId;
SceneId = sceneId;
SubjectId = subjectId;
TemplateId = templateId;
status = statu;
}
// 调试方法
public void PrintRoomData()
{
Debug.Log($"房间: {RoomId}, 场景: {SceneId}, 科目: {SubjectId}, 模板: {TemplateId}, 状态: {status}");
}
void OnBoolAChanged(bool value)
{
// 更新 bool 的值
isadministrator = value;
}
// Update is called once per frame
void Update()
{
if(type.text=="进行中")
{
isOngoing=true;
}
if (type.text == "已结束")
{
isEnd = true;
three.SetActive(false);
}
if(type.text=="已预订")
{
isScheduled=true;
if(isParticipate)
{
three.SetActive(true);
await += Time.deltaTime;
if (await >= time)
{
pop.gameObject.SetActive(false);
arrow.gameObject.SetActive(false);
}
}
else
{
three.SetActive(false);
}
}
}
void OnClickBtn()
{
if(isOngoing)
{
//Reserve.SetActive(true);
Debug.Log("正在进行中");
//return;
}
if (isEnd)
{
if (isadministrator)
{
Assessmentreport.gameObject.SetActive(true);
Review.gameObject.SetActive(true);
if (!eventAdded)
{
//点击生成评估报告
//Assessmentreport.onClick.AddListener(OnClickAssessmentreport);
Review.onClick.AddListener(OnClickReviewBtn);
eventAdded = true;
}
}
}
if(isScheduled)
{
if (isadministrator)
{
repair.gameObject.SetActive(true);
cancelbooking.gameObject.SetActive(true);
if (!eventAdded)
{
repair.onClick.AddListener(OnClickrepairBtn);
cancelbooking.onClick.AddListener(OnClickCancelBtn);
eventAdded = true;
}
}
}
}
void OnClickAssessmentreport()
{
Debug.Log("评估报告");
Game.uiManager.ShowUI<Image>("Panelreport");
UIClose();
}
void OnClickReviewBtn()
{
Debug.Log("复盘");
SceneManager.LoadScene("yhj 1");
}
void OnClickrepairBtn()
{
Debug.Log("修改");
}
void OnClickCancelBtn()
{
Debug.Log("取消预订");
}
void OnDestroy()
{
// 取消事件监听,防止内存泄漏
if (drill != null)
{
drill.OnBoolAChanged -= OnBoolAChanged;
}
}
async void UIClose()
{
await Task.Delay(3000);
Game.uiManager.CloseUI("Panelreport");
}
}