80 lines
2.4 KiB
C#
80 lines
2.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Threading.Tasks;
|
|
public class Alertwindow : MonoBehaviour
|
|
{
|
|
private Button sure;
|
|
private Button cancel;
|
|
private bool isback=false;
|
|
public GameObject player; // 模拟的玩家对象
|
|
// 用于“强制下线”延时
|
|
public float forceOfflineDelay = 3f;
|
|
private GameObject peopleposition;
|
|
private List<GameObject> nameImage; // 存储所有角色标签的子物体
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
sure=transform.Find("bg/downbg/GameObject3/Sure").GetComponent<Button>();
|
|
cancel=transform.Find("bg/downbg/GameObject3/Cancel").GetComponent<Button>();
|
|
sure.onClick.AddListener(OnSureBtn);
|
|
cancel.onClick.AddListener(OnCancelBtn);
|
|
peopleposition = GameObject.Find("peopleposition").gameObject;
|
|
//获取所有子物体中的 Button 组件
|
|
nameImage = new List<GameObject>();
|
|
foreach (Transform child in peopleposition.transform)
|
|
{
|
|
// 查找每个子物体中的"bg"子物体
|
|
Transform bgTransform = child.Find("nameImage");
|
|
if (bgTransform != null)
|
|
{
|
|
nameImage.Add(bgTransform.gameObject);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
async void OnSureBtn()
|
|
{
|
|
Game.uiManager.CloseUI("PoPhost");
|
|
//主持人画面自动切换成演练未开始的布局
|
|
isback = true;
|
|
BoolValueChanged?.Invoke(isback);
|
|
Game.uiManager.CloseUI("Panel1_2");
|
|
// 根据Toggle的状态控制所有"nameImage"子物体的显示与隐藏
|
|
foreach (var bgObject in nameImage)
|
|
{
|
|
bgObject.SetActive(isback); // 显示或隐藏
|
|
}
|
|
//玩家三秒后强制下线
|
|
await StopDrillAsync(); // 使用 async/await 执行异步操作
|
|
|
|
|
|
}
|
|
void OnCancelBtn()
|
|
{
|
|
//此弹窗退出关闭
|
|
Game.uiManager.CloseUI("PoPhost");
|
|
|
|
|
|
}
|
|
public delegate void BoolValueChangedDelegate(bool newBoolValue);
|
|
public static event BoolValueChangedDelegate BoolValueChanged;
|
|
// 停止演练的异步方法:强制下线玩家,且切换回未开始界面
|
|
async Task StopDrillAsync()
|
|
{
|
|
// 1. 延时 3 秒强制下线玩家
|
|
await Task.Delay((int)(forceOfflineDelay * 1000)); // 延时3秒
|
|
isback= false;
|
|
// 强制下线玩家
|
|
|
|
}
|
|
}
|