Commit 07f29ee7 authored by ElderLich's avatar ElderLich

Fix an async UI update continued after the UI item was destroyed.

parent 23cf6fc8
...@@ -99,17 +99,31 @@ namespace MDPro3.UI ...@@ -99,17 +99,31 @@ namespace MDPro3.UI
if (index == 0) if (index == 0)
return; return;
await UniTask.WaitWhile(() => Program.instance.deckSelector.inTransition); try
{
await UniTask.WaitWhile(
() => Program.instance.deckSelector.inTransition,
cancellationToken: destroyCancellationToken);
for (int i = 0; i < transform.GetSiblingIndex(); i++) int siblingIndex = transform.GetSiblingIndex();
await UniTask.Yield(cancellationToken: destroyCancellationToken); for (int i = 0; i < siblingIndex; i++)
await UniTask.Yield(cancellationToken: destroyCancellationToken);
if (gameObject == null) if (this == null || gameObject == null)
return; return;
var sprite = await Program.items.LoadDeckCaseIconAsync(deckCase, "_L_SD");
if (this == null || gameObject == null || sprite == null)
return;
var sprite = await Program.items.LoadDeckCaseIconAsync(deckCase, "_L_SD");
if (sprite != null)
Manager.GetElement<Image>("DeckImage").sprite = sprite; Manager.GetElement<Image>("DeckImage").sprite = sprite;
}
catch (System.OperationCanceledException)
{
}
catch (MissingReferenceException)
{
}
} }
protected override async UniTask RefreshAsync() protected override async UniTask RefreshAsync()
......
...@@ -87,13 +87,31 @@ namespace MDPro3.UI ...@@ -87,13 +87,31 @@ namespace MDPro3.UI
protected override async UniTask RefreshDeckCaseAsync() protected override async UniTask RefreshDeckCaseAsync()
{ {
await UniTask.WaitWhile(() => Program.instance.deckSelector.inTransition); try
for (int i = 0; i < transform.GetSiblingIndex(); i++) {
await UniTask.Yield(); await UniTask.WaitWhile(
() => Program.instance.deckSelector.inTransition,
cancellationToken: destroyCancellationToken);
int siblingIndex = transform.GetSiblingIndex();
for (int i = 0; i < siblingIndex; i++)
await UniTask.Yield(cancellationToken: destroyCancellationToken);
if (this == null || gameObject == null)
return;
var sprite = await Program.items.LoadDeckCaseIconAsync(deckCase, "_L_SD");
if (this == null || gameObject == null || sprite == null)
return;
var sprite = await Program.items.LoadDeckCaseIconAsync(deckCase, "_L_SD");
if (sprite != null)
Manager.GetElement<Image>("DeckImage").sprite = sprite; Manager.GetElement<Image>("DeckImage").sprite = sprite;
}
catch (System.OperationCanceledException)
{
}
catch (MissingReferenceException)
{
}
} }
protected override void OnClick() protected override void OnClick()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment