40 lines
1.0 KiB
C#
40 lines
1.0 KiB
C#
using System.Collections;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.Events;
|
|
|
|
namespace XWorld
|
|
{
|
|
//协程等待对话框关闭
|
|
public class WaitForDialogClose : CustomYieldInstruction
|
|
{
|
|
private bool _isClosed;
|
|
|
|
public override bool keepWaiting => !_isClosed; // 对话框未关闭时持续等待
|
|
|
|
public void OnDialogClosed() => _isClosed = true;
|
|
}
|
|
public class WaitDialogController
|
|
{
|
|
// 关闭事件(网页4的消息管理思想)
|
|
public UnityEvent OnClose;
|
|
WaitForDialogClose waitObj;
|
|
|
|
public void CloseDialog()
|
|
{
|
|
waitObj?.OnDialogClosed();
|
|
}
|
|
|
|
IEnumerator ShowDialogCoroutine(Button CloseButton)
|
|
{
|
|
CloseButton.onClick.AddListener(() =>
|
|
{
|
|
CloseDialog();
|
|
});
|
|
waitObj = new WaitForDialogClose();
|
|
yield return waitObj; // 协程在此处暂停,直到对话框关闭
|
|
|
|
}
|
|
}
|
|
|
|
} |