74 lines
2.1 KiB
C#
74 lines
2.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
public class Drill : MonoBehaviour
|
|
{
|
|
private Button ScheduledBtn;
|
|
public bool isadministrator; // 是否为管理员
|
|
private bool eventAdded = false; // 防止重复添加事件
|
|
public delegate void BoolChangedHandler(bool value);
|
|
public event BoolChangedHandler OnBoolAChanged;
|
|
|
|
private Text noRoomText; // "没有演练房间"的文本
|
|
private Transform content; // Scroll View Content
|
|
|
|
// 记录上一次的 isadministrator 状态,用于减少重复执行逻辑
|
|
private bool lastIsAdministratorState;
|
|
|
|
void Start()
|
|
{
|
|
ScheduledBtn = transform.Find("down/ScheduledBtn").GetComponent<Button>();
|
|
ScheduledBtn.gameObject.SetActive(false); // 初始隐藏按钮
|
|
|
|
noRoomText = transform.Find("Text").GetComponent<Text>();
|
|
noRoomText.gameObject.SetActive(false); // 初始隐藏文本
|
|
|
|
content = transform.Find("Mid/Scroll View/Viewport/Content");
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
// 实时检测房间列表是否为空,控制 noRoomText 的可见性
|
|
noRoomText.gameObject.SetActive(content.childCount == 0);
|
|
|
|
// 检测管理员状态是否发生变化
|
|
if (isadministrator != lastIsAdministratorState)
|
|
{
|
|
lastIsAdministratorState = isadministrator; // 更新状态记录
|
|
UpdateScheduledBtnVisibility(); // 更新按钮可见性
|
|
}
|
|
}
|
|
|
|
// 根据 isadministrator 状态实时更新 ScheduledBtn 的可见性
|
|
private void UpdateScheduledBtnVisibility()
|
|
{
|
|
if (isadministrator)
|
|
{
|
|
ScheduledBtn.gameObject.SetActive(true);
|
|
|
|
// 防止重复添加事件
|
|
if (!eventAdded)
|
|
{
|
|
ScheduledBtn.onClick.AddListener(OnClickScheduleBtn);
|
|
eventAdded = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ScheduledBtn.gameObject.SetActive(false);
|
|
}
|
|
|
|
// 触发事件,通知监听者
|
|
OnBoolAChanged?.Invoke(isadministrator);
|
|
}
|
|
|
|
// 演练计划按钮点击事件
|
|
void OnClickScheduleBtn()
|
|
{
|
|
Debug.Log("点击了演练计划按钮!");
|
|
// 这里可以添加具体逻辑
|
|
}
|
|
}
|