2026-07-09 예시
This commit is contained in:
@@ -47,10 +47,21 @@ private void OnDisable()
|
||||
_completion = null;
|
||||
}
|
||||
|
||||
// 대기 중인 선택을 취소하고 메뉴를 닫는다 (다른 NPC와 대화를 새로 시작할 때 등).
|
||||
// 취소된 쪽의 await Show(...)는 OperationCanceledException으로 빠져나간다.
|
||||
public void CancelPending()
|
||||
{
|
||||
_completion?.TrySetCanceled();
|
||||
}
|
||||
|
||||
public async Awaitable<int> Show(string choiceQuestion, List<DialogChoice> choices)
|
||||
{
|
||||
if (choices == null || choices.Count == 0) return 0;
|
||||
|
||||
// 이전 호출이 아직 대기 중이면 먼저 취소한다 (마지막 호출이 이긴다).
|
||||
// 취소된 쪽은 아래 finally까지 이 자리에서 정리를 마치고 빠져나간다.
|
||||
CancelPending();
|
||||
|
||||
SetQuestion(choiceQuestion);
|
||||
ClearRows();
|
||||
for (int i = 0; i < choices.Count; i++)
|
||||
@@ -63,17 +74,22 @@ public async Awaitable<int> Show(string choiceQuestion, List<DialogChoice> choic
|
||||
ResizeToRowCount(choices.Count);
|
||||
|
||||
_root.SetActive(true);
|
||||
_completion = new AwaitableCompletionSource<int>();
|
||||
var completion = new AwaitableCompletionSource<int>();
|
||||
_completion = completion;
|
||||
|
||||
int result;
|
||||
try
|
||||
{
|
||||
result = await _completion.Awaitable;
|
||||
result = await completion.Awaitable;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_completion = null;
|
||||
Hide();
|
||||
// 내가 아직 현재 세션일 때만 정리 — 취소 직후 다른 NPC가 새로 띄운 메뉴를 지우면 안 된다
|
||||
if (_completion == completion)
|
||||
{
|
||||
_completion = null;
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user