Files
Continentis/Assets/Scripts/MainGame/Commands/Cmd_WaitForUI.cs
SoulliesOfficial 61a397dd4c MOD!
2025-10-23 00:49:44 -04:00

38 lines
1.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using SLSFramework.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 outerContext)
{
if (waitableUI == null)
{
Debug.LogError($"指令无法找到UI元素指令将立即完成以避免队列卡死。");
return Observable.Return(Unit.Default);
}
// 1. 显示UI面板
waitableUI.Show();
// 2. 获取该面板的确认事件流,并附加一个副作用:
// 在确认事件发生后(即玩家点击按钮后),自动隐藏该面板。
return waitableUI.OnConfirm().Do(_ =>
{
if(autoHide) waitableUI.Hide();
});
}
}
}