Files
Continentis/Assets/Scripts/MainGame/Commands/Cmd_WaitForUI.cs

38 lines
1.2 KiB
C#
Raw Normal View History

2025-10-03 00:02:43 -04:00
using System;
2025-10-23 00:49:44 -04:00
using SLSFramework.General;
2025-10-03 00:02:43 -04:00
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;
}
2025-10-23 00:49:44 -04:00
protected override IObservable<Unit> OnExecute(CommandContext outerContext)
2025-10-03 00:02:43 -04:00
{
if (waitableUI == null)
{
Debug.LogError($"指令无法找到UI元素指令将立即完成以避免队列卡死。");
return Observable.Return(Unit.Default);
}
// 1. 显示UI面板
waitableUI.Show();
// 2. 获取该面板的确认事件流,并附加一个副作用:
// 在确认事件发生后(即玩家点击按钮后),自动隐藏该面板。
return waitableUI.OnConfirm().Do(_ =>
{
if(autoHide) waitableUI.Hide();
});
}
}
}