Skip to content

Commit e3dc839

Browse files
committed
fix: handle operation in animation button scaler
1 parent cdaf246 commit e3dc839

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

Assets/Code/UI/ButtonScaler.cs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Threading;
23
using UnityEngine;
34
using UnityEngine.EventSystems;
@@ -47,20 +48,32 @@ public void OnPointerUp(PointerEventData eventData)
4748
private async UniTaskVoid ScaleButtonAsync(Vector3 targetScale, float duration, CancellationToken token)
4849
{
4950
float time = 0f;
51+
if (_image == null)
52+
return;
53+
5054
Vector3 startScale = _image.transform.localScale;
5155

52-
while (time < duration)
56+
try
5357
{
54-
if (token.IsCancellationRequested)
55-
return;
58+
while (time < duration && !token.IsCancellationRequested)
59+
{
60+
if (this == null || _image == null)
61+
return;
5662

57-
float t = time / duration;
58-
_image.transform.localScale = Vector3.Lerp(startScale, targetScale, t);
59-
time += Time.unscaledDeltaTime;
60-
await UniTask.Yield(PlayerLoopTiming.Update, token);
61-
}
63+
float t = time / duration;
64+
_image.transform.localScale = Vector3.Lerp(startScale, targetScale, t);
65+
time += Time.unscaledDeltaTime;
66+
await UniTask.Yield(PlayerLoopTiming.Update, token);
67+
}
6268

63-
_image.transform.localScale = targetScale;
69+
if (this != null && _image != null)
70+
_image.transform.localScale = targetScale;
71+
}
72+
catch (OperationCanceledException)
73+
{
74+
75+
}
6476
}
77+
6578
}
6679
}

0 commit comments

Comments
 (0)