38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
|
|
using System;
|
|||
|
|
using SoulliesFramework.General;
|
|||
|
|
using UniRx;
|
|||
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
namespace Continentis.MainGame.Commands
|
|||
|
|
{
|
|||
|
|
public class Cmd_WaitForUI : CommandBase
|
|||
|
|
{
|
|||
|
|
private readonly WaitableUIElement waitableUI;
|
|||
|
|
private bool autoHide;
|
|||
|
|
|
|||
|
|
public Cmd_WaitForUI(WaitableUIElement waitableUI, bool autoHide = true)
|
|||
|
|
{
|
|||
|
|
this.waitableUI = waitableUI;
|
|||
|
|
this.autoHide = autoHide;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
protected override IObservable<Unit> OnExecute(CommandContext context)
|
|||
|
|
{
|
|||
|
|
if (waitableUI == null)
|
|||
|
|
{
|
|||
|
|
Debug.LogError($"指令无法找到UI元素,指令将立即完成以避免队列卡死。");
|
|||
|
|
return Observable.Return(Unit.Default);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 1. 显示UI面板
|
|||
|
|
waitableUI.Show();
|
|||
|
|
|
|||
|
|
// 2. 获取该面板的确认事件流,并附加一个副作用:
|
|||
|
|
// 在确认事件发生后(即玩家点击按钮后),自动隐藏该面板。
|
|||
|
|
return waitableUI.OnConfirm().Do(_ =>
|
|||
|
|
{
|
|||
|
|
if(autoHide) waitableUI.Hide();
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|