62 lines
1.7 KiB
C#
62 lines
1.7 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 Canvas preDrillPanel; // 演练未开始时的界面布局
|
|
// 用于“强制下线”延时
|
|
public float forceOfflineDelay = 3f;
|
|
// 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);
|
|
|
|
}
|
|
|
|
// 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");
|
|
//玩家三秒后强制下线
|
|
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;
|
|
// 强制下线玩家
|
|
|
|
}
|
|
}
|